Unhandled inspector error - {"code":-32000,"message":"Object reference chain is too long"} in selenoid - selenium

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.

Related

Selenium 4 and WebDriver implicitlyWait

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")));

clear() method doesn't clears the field in MS EDGE IE11 with Selenium-4.1.2

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();

Seleninum Chrome driver session error on docker

I'm using the docker image selenium/standalone-chrome:4.0.0 to run selenium, and yesterday just started to throw errors.
This is are my chrome web driver options:
val chromeOptions = ChromeOptions()
chromeOptions.setHeadless(isHeadless)
chromeOptions.addArguments(
"--whitelisted-ips",
"--no-sandbox",
"--disable-extensions",
"start-maximized",
"enable-automation",
"--disable-infobars",
"--disable-dev-shm-usage",
"--disable-browser-side-navigation",
"--disable-gpu", "window-size=1980,960"
)
The errors I'm getting are:
session deleted because of page crash from tab crashed (Session info: headless chrome=81.0.4044.92) Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'ip-10-0-3-6.eu-west-1.compute.internal', ip: '10.0.3.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.152-127.182.amzn2.x86_64', java.version: '1.8.0_242' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 81.0.4044.92, chrome: {chromedriverVersion: 81.0.4044.69 (6813546031a4b..., userDataDir: /tmp/.com.google.Chrome.LfBvAx}, goog:chromeOptions: {debuggerAddress: localhost:40023}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: none, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true} Session ID: bfce4fb924589b8929dc0351195352e1 *** Element info: {Using=id, value=XXXXX`
invalid session id Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'ip-10-0-3-6.eu-west-1.compute.internal', ip: '10.0.3.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.152-127.182.amzn2.x86_64', java.version: '1.8.0_242' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 81.0.4044.92, chrome: {chromedriverVersion: 81.0.4044.69 (6813546031a4b..., userDataDir: /tmp/.com.google.Chrome.LfBvAx}, goog:chromeOptions: {debuggerAddress: localhost:40023}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: none, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true} Session ID: bfce4fb924589b8929dc0351195352e1
If I need to add more code please let me know.
Thanks in advance!
It seems like some version(s) of Chrome seem to crash in Docker containers, on certain pages, due to too small /dev/shm.
To solve it, simply mount -v /dev/shm:/dev/shm
Or, longer, create a big shm
Started in privileged mode: docker run --privileged
Fix small /dev/shm size
docker exec $id sudo umount /dev/shm
docker exec $id sudo mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=512M tmpfs /dev/shm
Above is taken from here and credit goes to the respective owner.
You can also use Firefox and this should work without any problem.

IEdriver is driving me insane, seriously insane

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.

I'm using id as identifier to find element, but exception stack trace is showing css selector [duplicate]

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.