In our Selenium projects we use Implicit waits and fluent waits. Basically, we use Implicit waits until we need something explicit. E.g., for normal findElements() calls we depend on the implicit wait, but when waiting for an element to disappear after clicking some button we use a fluent wait. (See code below).
The problem is that lately I'm seeing a number of timeouts when calling implicityWait(n). This seems new. Maybe even in Selenium 4.3. Cannot say for sure, but it has certainly become bothersome. To be clear, "occasionally" means a couple of times over a couple of hundred tests (each calling implicitlyWait dozens of times).
public void waitUntilElementDisappear(By locator, int waitTime) throws Exception, TimeoutException {
Logger.log(String.format("Waiting [%ds] for [%s] to disappear", waitTime, locator));
try {
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(waitTime));
wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));
} catch (TimeoutException e) {
Logger.log("Caught timeout exception");
throw e;
} catch (Exception e) {
Logger.log(String.format("Caught exception message:[%s]", e.getMessage()));
throw e;
} finally {
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(DEFAULT_WAIT));
}
}
The issue occurs only in the finally block. (DEFAULT_WAIT is usually 180).
Any suggestions?
The exception:
org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'DESKTOP-8Q1PEBT', ip: '172.32.6.43', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.15'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [e8d45a02973053acad1a896d2ed471e6, setTimeout {implicit=0}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 103.0.5060.134, chrome: {chromedriverVersion: 103.0.5060.134 (8ec6fce403b..., userDataDir: C:\Users\jenkins\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:59791}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://172.32.6.43:4444/sessi..., se:cdpVersion: 103.0.5060.134, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: e8d45a02973053acad1a896d2ed471e6
at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:65)
I still see following in Chrome 104
10:48:48 Build info: version: '4.3.0', revision: 'a4995e2c09*'
10:48:48 System info: host: 'DESKTOP-8Q1PEBT', ip: '172.32.6.43', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.15'
10:48:48 Driver info: org.openqa.selenium.remote.RemoteWebDriver
10:48:48 Command: [f97c4a4cd7a0d468391badd20e23fe8f, setTimeout {implicit=240000}]
10:48:48 Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 104.0.5112.81, chrome: {chromedriverVersion: 104.0.5112.79 (3cf3e8c8a07d..., userDataDir: C:\Users\jenkins\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:56549}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://172.32.6.43:4444/sessi..., se:cdpVersion: 104.0.5112.81, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
10:48:48 Session ID: f97c4a4cd7a0d468391badd20e23fe8f]
10:48:48 org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException
Still not fixed in ChromeDriver. :(
I decided the only solution was to catch the exception and try again as
#pcalkins suggested.
public void setImplicitWait(int maxWaitTime) {
try {
this.driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(maxWaitTime));
} catch (TimeoutException e) {
this.driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(maxWaitTime));
}
}
Of course there could be a counter and a max retry, but so far I've found just 1 retry and it never fails.
I ended up wrapping a whole bunch of basic methods (e.g., findElement) in the same manner.
I know it is crude but so far seems to be my solution.
To bell the cat as per the Selenium Documentation:
Warning: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example, setting an implicit wait of 10 seconds and an explicit wait of 15 seconds could cause a timeout to occur after 20 seconds.
Solution
To simulate the expectation for checking for the element to be invisible you can use either of the following approaches:
Using invisibilityOf(WebElement element):
new WebDriverWait(driver, Duration.ofSeconds(waitTime)).until(ExpectedConditions.invisibilityOf(driver.findElement(By.cssSelector("ElementCss"))));
Using invisibilityOfElementLocated(By locator):
new WebDriverWait(driver, Duration.ofSeconds(waitTime)).until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("ElementCss")));
Related
Recently, I have upgraded my Selenium version from 2.53 to 4.1.2 to enable testing of our application on MS EDGE IE11. But we are continuously facing issue when we are clearing any TextBox field using simple Selenium .clear(). Although, its clearing that respective and but also throwing below exception.
Did anyone else facing similar kind of issues with Selenium-4.1.2 ?
Exception:
org.openqa.selenium.InvalidElementStateException: A JavaScript error
was encountered clearing the element. The driver assumes this is
because the element is hidden, disabled or read-only, and it must not
be to clear the element. Build info: version: '4.1.2', revision:
'9a5a329c5a' System info: os.name: 'Windows 10', os.arch: 'amd64',
os.version: '10.0', java.version: '1.8.0_222' Driver info:
org.openqa.selenium.ie.InternetExplorerDriver Command:
[69d06b0b-b468-455b-9d3c-24626ad40e16, clearElement
{id=2bb89cb8-5d24-4dd8-8e3a-be8fa7e1272e}] Capabilities
{acceptInsecureCerts: false, browserName: internet explorer,
browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal,
platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(),
se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0,
enablePersistentHover: true, ie.browserCommandLineSwitches: ,
ie.edgechromium: false, ie.edgepath: , ie.ensureCleanSession: false,
ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false,
ignoreProtectedModeSettings: false, ignoreZoomSetting: false,
initialBrowserUrl: http://localhost:54726/, nativeEvents: true,
requireWindowFocus: false}, setWindowRect: true,
strictFileInteractability: false, timeouts: {implicit: 0, pageLoad:
300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Element: [[InternetExplorerDriver: internet explorer on WINDOWS
(69d06b0b-b468-455b-9d3c-24626ad40e16)] -> id: userid] Session ID:
69d06b0b-b468-455b-9d3c-24626ad40e16 at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at
org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
at
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:558)
at
org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:251)
at
org.openqa.selenium.remote.RemoteWebElement.clear(RemoteWebElement.java:126)
Expectation : We expect clear() should clear the field without throwing any exception.
This is due to a bug in the Edge IE mode driver
https://github.com/SeleniumHQ/selenium/issues/10488
A possible workaround would be to use JavascriptExecutor to locate and clear the input field
JavascriptExecutor jsExec = (JavascriptExecutor)driver;
jsExec.executeScript("document.getElementById('field_to_clear').value=''");
InvalidElementStateException indicates that a WebElement is in a certain state in which actions cannot be performed with it. A couple of examples would include an element being obscured by another when clicking, or perhaps not being visible on the DOM.
Solution
It is always recommened that to clear any <input> field you need to induce WebDriverWait to elementToBeClickable() for the element (JavaScript) to render the HTML DOM completely before you invoke click() as follows:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("element_cssSelector"))).clear();
Selenoid version - 1.10.0
Chrome version - 85.0
Docker image - selenoid/vnc_chrome:81.0
Exception -
org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {"code":-32000,"message":"Object reference chain is too long"}
(Session info: chrome=80.0.3987.87)
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'mani-zt254', ip: 'fe80:0:0:0:4b9:53da:b2d:19d3%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 80.0.3987.87, chrome: {chromedriverVersion: 80.0.3987.16 (320f6526c1632..., userDataDir: /tmp/.com.google.Chrome.g10u57}, goog:chromeOptions: {debuggerAddress: localhost:45089}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: accept}
Session ID: 53b76f85512a10c9c08655240eef4042
Scenario
The above exception occurs while finding an element/performing any operation using jquery 1.x versions
So I inject the latest jQuery 3.5.0 able to perform the actions using jquery but some pages some jquery methods conflict occur due to this some errors occur in browser console click is not working in some elements, the above problems are there chrome 80.0 and above versions, now I'm using chrome 85.0.
Probably instead of calling:
evaluate_script
You should call:
execute_script
To elaborate. There is not so much information in the question itself, but in the feature test, if you are calling a script to be executred, you should call it with execute_script and not with evaluate_script
But there is not so much information in the question form a year or so, so just giving a wild quess.
I'm losing the will to live with IE 11 on an windows 2016 box.
I inherited this windows box, and the test code. I'm not a tester, but nobody else will help.
compile 'org.seleniumhq.selenium:selenium-java:3.12.0'
and have downloaded and I can confirm I'm using IEdriverServer 32 bit V 3.12
I've tried messing around with the security settings until I got extremely bored, and I've tried adding the poxy registry change for Windows.
I keep getting this error message at least once in my test suite though. I can navigate to the proper url in IE no problem from the server.
org.openqa.selenium.WebDriverException: Failed to navigate to http://properurl. This usually means that a call to the COM method IWebBrowser2::Navigate2() failed.
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'hostname', ip: 'yada yada', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(direct), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ie.usePerProcessProxy: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:54081/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Here's the code
System.setProperty("webdriver.ie.driver", ReadProperties.machine("ie_driver"));
InternetExplorerOptions options = new InternetExplorerOptions();
// options.introduceFlakinessByIgnoringSecurityDomains();
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setProxyType(org.openqa.selenium.Proxy.ProxyType.DIRECT);
options.setProxy(proxy);
REAL_DRIVER = new InternetExplorerDriver(options);
It doesn't always happen in the same test, but it ALWAYS happens at least once.
What is also happening is that the tests now take an incredible length of time, which case the CPU to max out, which makes the tests never complete.
If anyone has any suggestions, or ideas to get more information from the debugging, or even words of encouragement to coerce me into destroying the Windows box, I would be more than happy.
The tests all run perfectly fine in Chrome, obviously.
This question already has answers here:
Official locator strategies for the webdriver
(2 answers)
Closed 3 years ago.
I'm using Selenium Web driver with Java code. Whenever org.openqa.selenium.NoSuchElementException occurs, stack trace prints identifier method as css selector every time although I have used id to find web element.
I tried using xpath identifier and it prints perfect stack trace with correct identifier method. My sample code.
public void testMethod()
{
try
{
driver.findElement(By.id("test"));
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
Stack trace output:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#test"}
(Session info: chrome=75.0.3770.100)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'DTB150', ip: '10.37.55.150', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.90 (a6dcaf7e3ec6f..., userDataDir: C:\Users\DEV~1.SOL\AppData\...}, goog:chromeOptions: {debuggerAddress: localhost:38152}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: b6c8f6cd722e746281dd59657850e10f
*** Element info: {Using=id, value=test}
Check method in first line of exception. It says method: css selector although I'm using id to find element.
Is that some kind of error or I have misunderstood something or some problem with my code?
See the exception : Unable to locate element: {"method":"css selector","selector":"#test"}
in css selector # represent an id.
If id is test and you are using it like this :
driver.findElement(By.id("test"));
Exception should be related to id if not found.
But if you are using it like
driver.findElement(By.cssSelector("#test"));
You would get the same exception as mentioned above in OP.
I am trying to click on few elements using below code on one webpage but it gives element is not interactable error. I also applied wait condition but it didn't help.
Here is my code:
driver.get("https://www.cleartrip.com/flights/results?from=BDQ&to=PNQ&depart_date=13/04/2019&adults=1&childs=0&infants=0&class=Economy&airline=&carrier=&intl=n&sd=1555000238907&stops=1&departureTime=0_8");
driver.findElement(By.xpath("//input[#value='1' and #name = 'stops']")).click();
driver.findElement(By.xpath("//input[#value='2' and #name = 'stops']")).click();
driver.findElement(By.xpath("//input[#value='0_8' and #name = 'departureTime']")).click();
error :
FAILED: testFlightSearch
org.openqa.selenium.ElementNotVisibleException: element not interactable
(Session info: chrome=73.0.3683.86)
(Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'DESKTOP-B0K7HHH', ip: '192.168.43.195', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 73.0.3683.20 (8e2b610813e16..., userDataDir: C:\Users\shakti\AppData\Loc...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:62726}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 73.0.3683.86, webStorageEnabled: true}
Session ID: 8931562f8f37533e51073920887d83b0
The elements that you are trying the click are present on the page but are not clickable/interactable and that's the reason you are getting element not interactable exception.
You need to pick elements by using the xpath mentioned below and it would work:
driver.get("https://www.cleartrip.com/flights/results?from=BDQ&to=PNQ&depart_date=13/04/2019&adults=1&childs=0&infants=0&class=Economy&airline=&carrier=&intl=n&sd=1555000238907&stops=1&departureTime=0_8");
driver.findElement(By.xpath("//label[#for='1_1_1']")).click();
driver.findElement(By.xpath("//label[#for='1_1_2']")).click();
driver.findElement(By.xpath("//label[#for='1_1_0_8_departureTime']")).click();
The reason why you are getting org.openqa.selenium.ElementNotVisibleException is because when selenium goes to that URL, there is a progress bar on top of page which is still loading contents of the page. While it is loading, your code is searching for first element to click but it has not yet been loaded in the DOM.
You need to wait for the progress bar to complete loading before triggering the element click. The progress bar when loading has xpath: //p[#class='loadState tCenter' and contains(text(), 'Getting prices and availability...')] and after loading completely, the xpath to look for is //p[#class='loadState tCenter' and contains(text(), 'Your search results are ready.')].
Add a wait for element to appear for the 2nd xpath above and once it is visible, then trigger the element click.