Get this warning with latest Chromedriver: Unable to evaluate script: disconnected: not connected to DevTools . How to resolve this? - selenium

I get this warning in eclipse : Unable to evaluate script: disconnected: not connected to DevTools when running cucumber selenium script.
image of the warning
I am using the latest Chrome driver version. Since this issue, the following code does not give the out put.
enter code here public boolean isMixedContentWarningsAppearing() {
String warning = null;
boolean result = true;
try {
LogEntries entry = driver.manage().logs().get(LogType.BROWSER);
List<org.openqa.selenium.logging.LogEntry> logs = entry.getAll();
for (org.openqa.selenium.logging.LogEntry e : logs) {
if (e.toString().contains("Accessing")) {
System.out.println("..... warnings...." + e);
warning = e.toString();
// Reporter.addStepLog(warning);
}
}
} catch (Exception e) {
}
if (warning == null) {
result = false;
Reporter.addStepLog("No MixedContent warnings");
} else {
result = true;
Reporter.addStepLog("The application contains Mixed Contents");
}
return result;
}
can anybody help me to run this code?

Related

(React Native) Huawei Location Kit - is there any way to know if network location services setting switch off?

to make our apps working indoor to fetch location we need Network Location Services switch to be on
And we're using this function to detect any setting that still off
We noticed the response which is LocationSettingsStates, when the switch on or off is always true
Am I using wrong function to detect it??
The class and methods mentioned in the original post are the right ones to be used for checking network location service availability.
Please refer to a partial code extracted from Huawei sample code obtained from Github
public void checkSettings(View view) {
new Thread() {
#Override
public void run() {
try {
CheckSettingsRequest checkSettingsRequest = new CheckSettingsRequest();
LocationRequest locationRequest = new LocationRequest();
checkSettingsRequest.setLocationRequest(locationRequest);
checkSettingsRequest.setAlwaysShow(false);
checkSettingsRequest.setNeedBle(false);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(checkSettingsRequest.getLocationRequest())
.setAlwaysShow(checkSettingsRequest.isAlwaysShow())
.setNeedBle(checkSettingsRequest.isNeedBle());
settingsClient.checkLocationSettings(builder.build())
.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
#Override
public void onComplete(Task<LocationSettingsResponse> task) {
if (task != null && task.isSuccessful()) {
LocationSettingsResponse response = task.getResult();
if (response == null) {
return;
}
LocationSettingsStates locationSettingsStates =
response.getLocationSettingsStates();
stringBuilder.append(",\nisLocationPresent=")
.append(locationSettingsStates.isLocationPresent());
stringBuilder.append(",\nisLocationUsable=")
.append(locationSettingsStates.isLocationUsable());
stringBuilder.append(",\nisNetworkLocationUsable=")
.append(locationSettingsStates.isNetworkLocationUsable());
stringBuilder.append(",\nisNetworkLocationPresent=")
.append(locationSettingsStates.isNetworkLocationPresent());
stringBuilder.append(",\nisHMSLocationUsable=")
.append(locationSettingsStates.isHMSLocationUsable());
stringBuilder.append(",\nisHMSLocationPresent=")
.append(locationSettingsStates.isHMSLocationPresent());
LocationLog.i(TAG, "checkLocationSetting onComplete:" + stringBuilder.toString());
}
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(Exception e) {
LocationLog.i(TAG, "checkLocationSetting onFailure:" + e.getMessage());
int statusCode = 0;
if (e instanceof ApiException) {
statusCode = ((ApiException) e).getStatusCode();
}
switch (statusCode) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
android.util.Log.i(TAG,
"Location settings are not satisfied. Attempting to upgrade "
+ "location settings ");
try {
// Show the dialog by calling startResolutionForResult(), and check the
// result in onActivityResult().
if (e instanceof ResolvableApiException) {
ResolvableApiException rae = (ResolvableApiException) e;
rae.startResolutionForResult(CheckSettingActivity.this, 0);
}
} catch (IntentSender.SendIntentException sie) {
android.util.Log.i(TAG, "PendingIntent unable to execute request.");
}
break;
default:
break;
}
}
});
} catch (Exception e) {
LocationLog.i(TAG, "checkLocationSetting exception:" + e.getMessage());
}
}
}.start();
}
The execution results when “network location service” is turned on and off are shown below. It shows the state with true and false respectively.
In some phone, LocationSettings interface may not be able to get the exact state.
You can set the Priority to be PRIORITY_BALANCED_POWER_ACCURACY and use requestLocationUpdatesWithCallback interface to get location update.
If the network location is not enabled, you will get the error code NETWORK_LOCATION_SERVICES_DISABLED 10105.
Then it means the switch is not enabled.

wait.until(ExpectedCondition) generating error

After upgrading to selenium Java 3.8.1 the wait.until(ExpectedCondition) has started giving error message.
For the following piece of code
WebElement framei = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='ctl00_ContentPlaceHolder1_dlgModal_IFrame']")));
driver.switchTo().frame(framei);
WebElement AcceptRadioButton=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id='RblStatus']/tbody/tr[1]/td/label")));
AcceptRadioButton.click();
The following error is given:
Type The method until(Function<? super WebDriver,V>) in the type FluentWait<WebDriver> is not applicable for the arguments (ExpectedCondition<WebElement>)
I tried to resolve the following issue by removing the Selenium java version 3.8.1 of
Same problem as you but not so sure about Eugene S answer I search in sources of selenium-java 2.53.1 and 3.8.1 to see what was different between FluentWait class. Here are until fonctions of the different version:
2.53.1 :
public void until(final Predicate<T> isTrue) {
until(new Function<T, Boolean>() {
public Boolean apply(T input) {
return isTrue.apply(input);
}
public String toString() {
return isTrue.toString();
}
});
}
OR
public <V> V until(Function<? super T, V> isTrue) {
long end = clock.laterBy(timeout.in(MILLISECONDS));
Throwable lastException = null;
while (true) {
try {
V value = isTrue.apply(input);
if (value != null && Boolean.class.equals(value.getClass())) {
if (Boolean.TRUE.equals(value)) {
return value;
}
} else if (value != null) {
return value;
}
} catch (Throwable e) {
lastException = propagateIfNotIgnored(e);
}
// Check the timeout after evaluating the function to ensure conditions
// with a zero timeout can succeed.
if (!clock.isNowBefore(end)) {
String message = messageSupplier != null ?
messageSupplier.get() : null;
String toAppend = message == null ?
" waiting for " + isTrue.toString() : ": " + message;
String timeoutMessage = String.format("Timed out after %d seconds%s",
timeout.in(SECONDS), toAppend);
throw timeoutException(timeoutMessage, lastException);
}
try {
sleeper.sleep(interval);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new WebDriverException(e);
}
}
}
AND IN 3.8.1:
public <V> V until(Function<? super T, V> isTrue) {
long end = clock.laterBy(timeout.in(MILLISECONDS));
Throwable lastException;
while (true) {
try {
V value = isTrue.apply(input);
if (value != null && (Boolean.class != value.getClass() || Boolean.TRUE.equals(value))) {
return value;
}
// Clear the last exception; if another retry or timeout exception would
// be caused by a false or null value, the last exception is not the
// cause of the timeout.
lastException = null;
} catch (Throwable e) {
lastException = propagateIfNotIgnored(e);
}
// Check the timeout after evaluating the function to ensure conditions
// with a zero timeout can succeed.
if (!clock.isNowBefore(end)) {
String message = messageSupplier != null ?
messageSupplier.get() : null;
String timeoutMessage = String.format(
"Expected condition failed: %s (tried for %d second(s) with %s interval)",
message == null ? "waiting for " + isTrue : message,
timeout.in(SECONDS), interval);
throw timeoutException(timeoutMessage, lastException);
}
try {
sleeper.sleep(interval);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new WebDriverException(e);
}
}
}
I don't see any difference between the three functions arguments but the project I work on did not return me any error with 2.53.1 version but with 3.8.1 I have the same error than Akhil.
As it says in the error message:
FluentWait<WebDriver> is not applicable for the arguments (ExpectedCondition<WebElement>)
Starting from Selenium 3, until method declaration now looks like this:
public <V> V until(Function<? super T, V> isTrue)
where Function is:
public interface Function<T, R>
So it has been converted to use Java 8 functional interface. You will need to rewrite your expected conditions accordingly.
As per best practices we must try to switch to a <iframe> with proper WebDriverWait as follows :
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[#id='ctl00_ContentPlaceHolder1_dlgModal_IFrame']")));

How Selenium getPageSource() work when we use switchTowindow is used?

What driver.getPageSource() method return if I switch the driver to some other window i have checked it is returning me the page source of the first page i.e. the first webpage I have launched how to get page source of current switched window..without relaunching the page....??
I have written the code like this I am successfully switching to the new window..but unable to get page source of current window...
public boolean switchToWindow(String title)
{
Set<String> availableWindows = webDr.getWindowHandles();
if (availableWindows.size() > 1)
{
try
{
for (String windowId : availableWindows)
{
if(webDr.switchTo().window(windowId).getTitle().equals(title))
{
return true;
}
}
} catch (Exception e) {
logger.handleError("No child window is available to switch ", e);
}
}
return false;
}
driver.getPageSource() should return the current active window source. From your code you can call driver.getPageSource() after switching to window.
public boolean switchToWindow(String title)
{
Set<String> availableWindows = webDr.getWindowHandles();
if (availableWindows.size() > 1)
{
try
{
for (String windowId : availableWindows)
{
if(webDr.switchTo().window(windowId).getTitle().equals(title))
{
System.out.println(driver.getPageSource());
return true;
}
}
} catch (Exception e) {
logger.handleError("No child window is available to switch ", e);
}
}
return false;
}

How can I avoid "no response from server URL" exception when using hub on Selenium remotewebdriver when object is not found?

This is the code I am getting error on line 1. Instead of returning true or false it throws an exception " No response from server for url: http://test:4444/wd/hub/session/1382359342795/element
Getting error on line1 :
Boolean tInputElement = driver.FindElement(By.Id("locator")).Enabled;
if (tInputElement.ToString() == "True")
{
IWebElement InputElement=driver.FindElement(By.Id("locator"));
InputElement.SendKeys(InputData);
}
Please suggest how can I avoid no response error and catch objectnotfoundexception. Please note I am running this code using Hub.
This is how I got this working :
int _TotalTimeToWait = 0;
int TotalTimeToWaitinSecs = 40;
while (_TotalTimeToWait < TotalTimeToWaitinSecs && driver.FindElements(by).Count == 0)
{
Thread.Sleep(1000);
_TotalTimeToWait++;
}
if (_TotalTimeToWait == 0) { driver.FindElement(by).Click(); Thread.Sleep(2000); }
else { throw new ElementNotVisibleException(); }
_TotalTimeToWait = 0;
As far as i know, there is no property like Enabled for WebElement, but it does have a IsEnabled() method, so try:
if (driver.FindElement(By.Id("locator")).isEnabled())
{
IWebElement InputElement=driver.FindElement(By.Id("locator"));
InputElement.SendKeys(InputData);
}
Or something like:
IWebElement InputElement=driver.FindElement(By.Id("locator"));
if (InputElement != null && InputElement.isEnabled())
{
InputElement.SendKeys(InputData);
}

JavaMail - Pop3Folder accidentally gets closed

After successfully opening Pop3Folder, and retrieving messages from it, I then sometimes get to the point, when folder.isOpen returns false. At the same time, when looking at the Pop3Folder's fields in debug mode, I see that the field opened set to true.
Could somebody give me a hint, what might go wrong here?
Here is the code:
public void popMail(MessageProcessor messageProcessor) throws MessagingException {
Folder inboxFolder = null;
Store store = null;
try {
store = mailSession.getStore();
store.connect(mailSession.getProperty("mail.user"),
mailSession.getProperty("mail.password"));
// OK. Connected to POP3 Store.
inboxFolder = store.getFolder("inbox");
inboxFolder.open(Folder.READ_WRITE);
// The folder is successfully opened.
Message[] msgs = inboxFolder.getMessages();
// Messages are successfully retrieved.
if (msgs != null && msgs.length > 0) {
for (Message msg : msgs) {
if (messageProcessor != null) {
// Calling custom listener to process message
messageProcessor.processMessage(msg);
}
msg.setFlag(Flag.DELETED, true);
}
}
} finally {
// Oops, inboxFolder.isOpen returns false.
// Meanwhile I see in debug mode that inboxFolder#opened is set to true
if (inboxFolder != null && inboxFolder.isOpen()) {
try {
inboxFolder.close(true);
} catch (MessagingException e) {
log.warn("Error while closing folder");
}
} if (store != null) {
try {
store.close();
} catch (MessagingException e) {
log.warn("Error while closing store");
}
}
}
}
The server may be timing out the connection if your processMessage method takes too long. Turn on Session debugging and examine the protocol trace for clues.