node.jsgoogle-chromeselenium-webdriver

Executing JavaScript on Chrome 130+ with Selenium 3


On project I work on we are still on Selenium 3.6 (nodejs) which for the specifics of the application requires executing JavaScript code and this worked until Chrome 130. It's worth mentioning this is still working in Firefox. I am aware of this working on latest v4 selenium but right now switching to Selenium 4 might be a problem for me.

So back to the question - I've been searching if this is something related to how JsonWwire Protocol works and if there is anything changed there but didn't find any answer. Has anyone had this issue and how did you solve it?

For people who will ask for code snippet here is one:

let element = this.driver.wait(until.elementLocated(By.css(selector)), waitTimeout);

await this.driver.wait(until.elementIsVisible(element), waitTimeout);
await this.driver.wait(until.elementIsEnabled(element), waitTimeout);
await this.driver.executeScript('arguments[0].scrollIntoView(true);', element);

The above code produces the following error:

JavascriptError: javascript error: Cannot read properties of undefined (reading 'scrollIntoView')
  (Session info: chrome=131.0.6778.86)
  (Driver info: chromedriver=131.0.6778.85 (3d81e41b6f3ac8bcae63b32e8145c9eb0cd60a2d-refs/branch-heads/6778@{#2285}),platform=Windows NT 10.0.19045 x86_64)

Solution

  • Turns out this is a bug in recent chromedriver which is supposed to get fixed with next release:

    https://issues.chromium.org/issues/379584343
    https://chromium-review.googlesource.com/c/chromium/src/+/6063257