Crash when trying to set pageloadtimeout in Selenium 3.6 - selenium

I am trying to upgrade my project from Selenium 3.0.0beta4 to 3.6.0. I want to set the timeout for page loading with
driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
This, however, crashes the application:
Exception in thread "main" org.openqa.selenium.InvalidArgumentException:
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'machine.example.org', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.88', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=/tmp/rust_mozprofile.AZHGaB47hL8x, rotatable=false, timeouts={implicit=0, page load=300000, script=30000}, pageLoadStrategy=normal, platform=LINUX, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=true, browserVersion=52.4.0, platformVersion=4.4.88, moz:processID=10959, browserName=firefox, javascriptEnabled=true, platformName=LINUX}]
The value is not changed. I am using geckodriver v0.18.0 and Firefox 52.4.0.
Is there any limitation on the Firefox version I can use?

In the Selenium 3.0.0beta4 version of my application I set the following property for the gecko driver:
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
After I changed the property to
System.setProperty("webdriver.firefox.marionette", "/path/to/geckodriver");
in the Selenium 3.6.0 version my application started working again. I use Firefox v45.9.0 and geckodriver v0.18.0. Other combinations may work, too.

Related

Selenium highlight working only on one specific machine

Selenium code to highlight an element is working only on one of the system.
I have updated chrome and chrome driver on both of them but in one machine, it works but code breaks on another machine when trying to highlight the page element.
Below is the exception:
An error occurred while fetching element : Expected condition failed: waiting for visibility of element located by By.id: body_x_grid_x__ctl2__ctl0 (tried for 15 second(s) with 500 MILLISECONDS interval)
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: '**', ip: '**', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_77'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab), userDataDir=**}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=67.0.3396.99, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=false, acceptInsecureCerts=false, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: 9854688adcdbe56519b9869c496b58e2
at com.selenium.element.action.Wait.elementAction(Wait.java:68)
....
It does not find the element within specific periods and breaks.
This error message...
An error occurred while fetching element : Expected condition failed: waiting for visibility of element located by By.id: body_x_grid_x__ctl2__ctl0 (tried for 15 second(s) with 500 MILLISECONDS interval)
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: '**', ip: '**', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_77'
...implies that the ChromeDriver was unable to interact with the WebElement returned after WebDriverWait.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
Your Selenium Client and ChromeDriver versions are not getting detected back.
Your JDK version is 1.8.0_77 which is pretty ancient.
So there is a clear mismatch between the JDK v8u77 and the latest Selenium Client v3.13.0 , ChromeDriver v2.40 and the Chrome Browser v67.0
Solution
Upgrade JDK to recent levels JDK 8u172.
Upgrade Selenium to current levels Version 3.13.0.
Keep ChromeDriver to current ChromeDriver v2.40 level.
Keep Chrome version between Chrome v66-68 levels. (as per ChromeDriver v2.40 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Execute your #Test.
Wrap your code in a try/catch clause, and inside the catch save the content of webdriver.getPageSource(). Then examine its content (you may even be able to open it in the browser if you name the file with a .html extension) and see whether an element with id='body_x_grid_x__ctl2__ctl0' actually exists.
I'm not sure, but it looks like this id was generated automatically by the application, and may be generated somewhat differently on the other machine.
Your problem is not with highlighter, it's with your webElement:
An error occurred while fetching element : Expected condition failed: waiting for visibility of element located by By.id: body_x_grid_x__ctl2__ctl0 (tried for 15 second(s) with 500 MILLISECONDS interval)
Increase the wait time because your existing wait in 15 sec: increase according to your website page load maximum time:
WebDriverWait wait = new WebDriverWait(driver, wait time in second);
WebElement we = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("your xpath")));
After getting the webElement you can go for highlighter by using below code:
public void highLighter(WebDriver driver, WebElement we) {
try{
JavascriptExecutor js = (JavascriptExecutor)driver;
String var = (String) js.executeScript("return arguments[0].getAttribute('style', arguments[1]);", we);
js.executeScript("return arguments[0].setAttribute('style', arguments[1]);", we,"border:4px solid red;");
Thread.sleep(200);
js.executeScript("return arguments[0].setAttribute('style', arguments[1]);", we,var);
}catch(Exception e){
System.out.println("unable to HighLight");
}
}

Selenium - Unable to Create a remote session. [FF 53.0.2 + Geckodriver 0.16 + Selenium 3.4]

I can able to see the FF[53.0.2] opened. But, I am getting an "error Unable to create new remote session". Could any one help out?
Environment :
Windows 7 64 bit
FF - 53.0.2 (32bit)
Selenium 3.4
Geckdriver 0.16 and 0.16.1[win 32]
Problem :
Unable to create a new remote session. But, driver initiated the FF [blank browser].
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\src\\Drivers\\geckodriver-‌v0.16.0-win32\\gecko‌​driver.exe");
DesiredCapabilities caps2 = DesiredCapabilities.firefox();
caps2.setBrowserName("firefox"‌​);
caps2.setPlatform(‌​org.openqa.selenium.‌​Platform.WINDOWS);
dr‌​iver1= new RemoteWebDriver(new URL(node),caps2);
Actual output :
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}, version=, platform=VISTA}], required capabilities = Capabilities [{moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}}]
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'XXXXXXXXX', ip: 'XXX.XXX.XX.XXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: driver.version: FirefoxDriver
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10 09:00:17 -0800'
System info: host: 'XXXXXXXXX', ip: 'XXX.XXX.XX.XXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: driver.version: FirefoxDriver
Why don't you try replacing this
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\src\\Drivers\\geckodriver-‌​v0.16.0-win32\\gecko‌​driver.exe");
With this:
System.setProperty("webdriver.gecko.driver", "explicit path to your geckodriver);
I got this issue resolved.While setting up a node, i gave the configuration as geckodriver-‌​v0.16.1-win32. Irrespective of setting other properties, it didn't change.Simple one, but i took a long way to explore. Anyways, thank you guys.

Unable to load selenium chrome driver from maven class path

i am running selenium for chrome and need to open google page. i am using testng and i have my chrome driver in the path \src\test\resources. i use jdk 1.8 and windows 64
i use the below code and i am not able to load successsfully
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("chromedriver-2.27.exe").getFile());
String path=file.getAbsolutePath();
System.setProperty("webdriver.chrome.driver",path);
WebDriver driver = new ChromeDriver();
driver.get("www.google.com");
i get error
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'NANSARI', ip: '172.18.240.141', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: driver.version: ChromeDriver
Please advise.
Try it this way and see if it works -
Put the ChromeDriver outside the project directory, say - C:\Selenium_Drivers
Code -
System.setProperty("webdriver.chrome.driver","C:\\Selenium_Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("www.google.com");
Please use the latest version of Selenium, ChromeDriver and Chrome

webdriver can't find element on UI

I'm trying to test search UI using selenium web driver in java
If I click on result it shows some properties of that results.
So now when I click on first result, the webdriver is able to locate those properties by FindElementsByXpath("//li[#class='clickable ng-binding ng-scope']")
Also tried findElementsByCss("*[class='clickable ng-binding ng-scope']")
But when webdriver clicks on second result, it shows up their properties but webdriver is UNABLE to locate properties (have same class name as first).
Any help here?
can't use Xpath since ids are unique and different.
i click result using this-
findElement(By.xpath("/html/body/div[1]/div/div/div[1]/div[2]/div[1]/div[2]/div/els-result["+num+"]/div")).click();
where num is result number
*Stack trace here
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of all elements located by By.cssSelector: *[class='clickable ng-binding ng-scope'] (tried for 15 second(s) with 500 MILLISECONDS interval)
Build info: version: '3.1.0', revision: '86a5d70', time: '2017-02-16 07:57:44 -0800'
System info: host: '', ip: '', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.3', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, appBuildId=20170125094131, version=, platform=MAC, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=22487, browserVersion=51.0.1, platformVersion=16.4.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=darwin, firefox_profile=UEsDBBQACAgIAOl6aUoAAAAAAAAAA..., unexpectedAlertBehaviour=dismiss}]
Session ID: df2df541-1966-5a4b-871c-7cd8c295f4eb
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:257)
at cucumber.stepdefination.DataSearch.FindElementsByCss(DataSearch.java:166)
at cucumber.stepdefination.AssestCountSD.assest_count_matches_list(AssestCountSD.java:76)
at cucumber.stepdefination.AssestCountSD.for_each_source_assest_count_matches_that_in_list_on_right(AssestCountSD.java:51)
at ✽.Then For each source assest count matches that in list on right(/Users/malikh/Documents/workspace/cucumber/src/test/resource/assetCount.feature:6)
I would suggest to use Firefox browser and install one of its extensions called 'Firepath'. This would help you to locate a UI element using both 'Xpath' and 'CSS'.

Webdriver: IE11: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed

While running my test scripts in win7 IE11 using Selenium WebDriver I am getting below error:
Error:
==============================================================================================
Started InternetExplorerDriver server (64-bit)
2.42.0.0
Listening on port 13127
org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Software
caused connection abort: recv failed
org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
JavaScript error (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 169 milliseconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'blr2261913', ip: '10.177.101.114', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_51'
Session ID: 71972154-3b97-4623-b651-aaa0bb460ffb
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=f
r=dismiss, version=11, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true,
e, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]
com.thoughtworks.selenium.SeleniumException: JavaScript error (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 169 milliseconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'blr2261913', ip: '10.177.101.114', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_51'
Session ID: 71972154-3b97-4623-b651-aaa0bb460ffb
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=f
r=dismiss, version=11, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true,
e, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]
at com.thoughtworks.selenium.webdriven.SeleneseCommand.apply(SeleneseCommand.java:44)
at com.thoughtworks.selenium.webdriven.Timer.run(Timer.java:40)
at com.thoughtworks.selenium.webdriven.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:143)
at com.thoughtworks.selenium.webdriven.WebDriverCommandProcessor.doCommand(WebDriverCommandProcessor.java:73)
at com.thoughtworks.selenium.DefaultSelenium.type(DefaultSelenium.java:317)
Env: Windows7-64 bit, IE11
IEDriver version: Latest i.e 2.42.0
Selenium Server: 2.41.0
I have already followed the steps mentioned https://code.google.com/p/selenium/wiki/InternetExplorerDriver ! NO LUCK!
Have searched enough over net but could not find any solution to my problem.
Any help will be highly appreciated.
Thanks in advance!
I'm not sure if this applies directly to your problem but I have come across something similar when I got the error:
Caused by: java.net.SocketException: Connection reset
Which lead me to a bug raised here: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7077696
You have recv failed in your error similar to this bug, however it was noted that it's more likely to be Windows Firewall causing the error rather than a bug. Some possible workarounds (from the site):
Run with -Djava.net.preferIPv4Stack=true
Add a firewall exception for the Java binary
Or disable stateful FTP inspection in the firewall
which I believe is done with: netsh advfirewall set global StatefulFTP disable
There is also an issue raised here: https://code.google.com/p/selenium/issues/detail?id=6437
Which applies to the error I have more so but it could possibly apply to yours? As comment #7 (from a project member) states there is a known issue with IE11.
This is may or may not help as I haven't had a chance to test the solutions and I'm not entirely sure of it myself!