webdriverio: WebdriverIO error out after clicking on a button

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

8.22

Node.js Version

v21.1.0

Mode

Standalone Mode

Which capabilities are you using?

{
        browserName: 'chrome',
        acceptInsecureCerts: true,
    },

What happened?

WebdriverIO errors out after clicking on a button and fails the test. There is no obvious reason for it to fail because I can watch it run the test from the Chrome browser. It clicks on the button (a save button, for example) and the web page saves the form data and navigates to the next expected page. So the click action flow works. However why WebdriverIO errors out.

Sample errors: -Error: Can’t call elementClick on element with selector “.ui-button-text=Create Document” because element wasn’t found

-Error: invalid selector: The selector “” used with strategy “css selector” is invalid! For more information on selectors visit the WebdriverIO docs at: https://webdriver.io/docs/selectors

NOTE: our web app is developed with https://www.primefaces.org/ library and java (). Interestingly hundreds of other buttons in the app work fine with WebdriverIO and only certain buttons would not work. This issue appears to be reproducible more often with Chrome browser. I tried browser.pause() or refresh() page before clicking on the button but not able to resolve the issue.

Any insights would be appreciated. Thanks.

What is your expected behavior?

No response

How to reproduce the bug.

n/a

Relevant log output

Sample errors:
-Error: Can't call elementClick on element with selector ".ui-button-text=Create Document" because element wasn't found

-Error: invalid selector: The selector "" used with strategy "css selector" is invalid! For more information on selectors visit the WebdriverIO docs at: https://webdriver.io/docs/selectors

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 32 (14 by maintainers)

Most upvoted comments

FWIW I get the same with Selenium, repro here: https://github.com/slhck/selenium-execution-context-error

Ah, probably you’re right, but this issue was the only one I found when I looked for my error. Sorry for the noise if it’s not relevant.

Thanks. My original issue described from this ticket remains. No solution yet.

@ryan-cubic how would this not be related when the error “no such execution context” is the same?

EDIT: All issues I have seen so far that throw this error seem to relate to an issue with chromedriver.

It might not be directly related to the exact issue I shared but the error seems to be related to something going wrong in chromedriver.

Since we cannot reproduce the issue like Christian said we can only provide information like this and make guesses instead of actually offer anything concrete.

I’m going to close the issue for now, feel free to reach out with a reproducible example. I personally would start by comparing what makes this button different from others, does it redirect while others do not? Does it have different html attributes? Etc

Based on the logs:

[0-0] 2023-11-16T03:19:15.236Z INFO webdriver: COMMAND findElement("css selector", "#import")
[0-0] 2023-11-16T03:19:15.236Z INFO webdriver: [POST] http://localhost:9515/session/94b1b9e5455202a98edcc115efab4c04/element
[0-0] 2023-11-16T03:19:15.236Z INFO webdriver: DATA { using: 'css selector', value: '#import' }
[0-0] 2023-11-16T03:19:15.242Z INFO webdriver: RESULT {
[0-0]   'element-6066-11e4-a52e-4f735466cecf': 'A8A3466952B076A7B89981BBED42D01F_element_348'
[0-0] }
[0-0] 2023-11-16T03:19:15.243Z INFO webdriver: COMMAND findElementFromElement("A8A3466952B076A7B89981BBED42D01F_element_348", "xpath", ".//button[normalize-space(text()) = "Import"] | .//button[not(.//button[normalize-space(text()) = "Import"]) and normalize-space() = "Import"]")
[0-0] 2023-11-16T03:19:15.244Z INFO webdriver: [POST] http://localhost:9515/session/94b1b9e5455202a98edcc115efab4c04/element/A8A3466952B076A7B89981BBED42D01F_element_348/element
[0-0] 2023-11-16T03:19:15.244Z INFO webdriver: DATA {
[0-0]   using: 'xpath',
[0-0]   value: './/button[normalize-space(text()) = "Import"] | .//button[not(.//button[normalize-space(text()) = "Import"]) and normalize-space() = "Import"]'
[0-0] }
[0-0] 2023-11-16T03:19:15.255Z INFO webdriver: RESULT {
[0-0]   'element-6066-11e4-a52e-4f735466cecf': 'A8A3466952B076A7B89981BBED42D01F_element_353'
[0-0] }
[0-0] 2023-11-16T03:19:15.257Z INFO webdriver: COMMAND getElementTagName("A8A3466952B076A7B89981BBED42D01F_element_353")
[0-0] 2023-11-16T03:19:15.257Z INFO webdriver: [GET] http://localhost:9515/session/94b1b9e5455202a98edcc115efab4c04/element/A8A3466952B076A7B89981BBED42D01F_element_353/name
[0-0] 2023-11-16T03:19:15.261Z INFO webdriver: RESULT button
[0-0] 2023-11-16T03:19:15.263Z INFO webdriver: COMMAND executeScript(<fn>, <object>)
[0-0] 2023-11-16T03:19:15.263Z INFO webdriver: [POST] http://localhost:9515/session/94b1b9e5455202a98edcc115efab4c04/execute/sync
[0-0] 2023-11-16T03:19:15.263Z INFO webdriver: DATA {
[0-0]   script: 'isElementDisplayed(...) [8007 bytes]',
[0-0]   args: [
[0-0]     {
[0-0]       'element-6066-11e4-a52e-4f735466cecf': 'A8A3466952B076A7B89981BBED42D01F_element_353',
[0-0]       ELEMENT: 'A8A3466952B076A7B89981BBED42D01F_element_353'
[0-0]     }
[0-0]   ]
[0-0] }
[0-0] 2023-11-16T03:19:15.268Z INFO webdriver: RESULT true
[0-0] 2023-11-16T03:19:15.269Z INFO webdriver: COMMAND elementClick("A8A3466952B076A7B89981BBED42D01F_element_353")
[0-0] 2023-11-16T03:19:15.269Z INFO webdriver: [POST] http://localhost:9515/session/94b1b9e5455202a98edcc115efab4c04/element/A8A3466952B076A7B89981BBED42D01F_element_353/click
[0-0] 2023-11-16T03:19:21.279Z DEBUG webdriver: request failed due to response error: stale element reference
[0-0] 2023-11-16T03:19:21.279Z WARN webdriver: Request encountered a stale element - terminating request
[0-0] 2023-11-16T03:19:21.279Z INFO webdriver: COMMAND findElement("css selector", "")
[0-0] 2023-11-16T03:19:21.280Z INFO webdriver: [POST] http://localhost:9515/session/94b1b9e5455202a98edcc115efab4c04/element
[0-0] 2023-11-16T03:19:21.280Z INFO webdriver: DATA { using: 'css selector', value: '' }
[0-0] 2023-11-16T03:19:21.296Z DEBUG webdriver: request failed due to response error: invalid selector
[0-0] 2023-11-16T03:19:21.296Z WARN webdriver: Request failed with status 400 due to The selector "" used with strategy "css selector" is invalid! For more information on selectors visit the WebdriverIO docs at: https://webdriver.io/docs/selectors

It seems like that you are fetching an element, clicking on it fails due to stale element exception and then the retry fails as well as the selector is not passed forward correctly. Is there any chance you can create a reproducible example?

Oh, today I got the same behaviour on 118 chrome. It actually clicks the button but gets the wrong response from chromedriver and tries to click it again but button is not there anymore. So before clicking:

[0-0] 2023-11-15T20:23:33.233Z INFO webdriver: COMMAND findElement("css selector", ".buy-now-btn")
[0-0] 2023-11-15T20:23:33.234Z INFO webdriver: [POST] http://0.0.0.0:55640/session/53e4f0d2a7876876adeadbcae4841f94/element
[0-0] 2023-11-15T20:23:33.234Z INFO webdriver: DATA { using: 'css selector', value: '.buy-now-btn' }
[0-0] 2023-11-15T20:23:33.500Z INFO webdriver: RESULT {
[0-0]   'element-6066-11e4-a52e-4f735466cecf': 'E7FC4846FB567E9D29E984C83B571B12_element_63'
[0-0] }
[0-0] 2023-11-15T20:23:33.504Z INFO webdriver: COMMAND executeScript(<fn>, <object>)
[0-0] 2023-11-15T20:23:33.504Z INFO webdriver: [POST] http://0.0.0.0:55640/session/53e4f0d2a7876876adeadbcae4841f94/execute/sync
[0-0] 2023-11-15T20:23:33.504Z INFO webdriver: DATA {
[0-0]   script: 'isElementDisplayed(...) [8007 bytes]',
[0-0]   args: [
[0-0]     {
[0-0]       'element-6066-11e4-a52e-4f735466cecf': 'E7FC4846FB567E9D29E984C83B571B12_element_63',
[0-0]       ELEMENT: 'E7FC4846FB567E9D29E984C83B571B12_element_63'
[0-0]     }
[0-0]   ]
[0-0] }
[0-0] 2023-11-15T20:23:33.572Z INFO webdriver: RESULT true

Clicking with ERROR:

[0-0] 2023-11-15T20:23:33.573Z INFO webdriver: COMMAND elementClick("E7FC4846FB567E9D29E984C83B571B12_element_63")
[0-0] 2023-11-15T20:23:33.574Z INFO webdriver: [POST] http://0.0.0.0:55640/session/53e4f0d2a7876876adeadbcae4841f94/element/E7FC4846FB567E9D29E984C83B571B12_element_63/click
[0-0] 2023-11-15T20:23:40.988Z DEBUG webdriver: request failed due to response error: no such execution context

And then RETRIES after click actually happend and button is not available anymore:

[0-0] 2023-11-15T20:23:40.988Z INFO webdriver: Retrying 1/3
[0-0] 2023-11-15T20:23:40.988Z INFO webdriver: [POST] http://0.0.0.0:55640/session/53e4f0d2a7876876adeadbcae4841f94/element/E7FC4846FB567E9D29E984C83B571B12_element_63/click
[0-0] 2023-11-15T20:23:40.988Z WARN webdriver: Request failed with status 400 due to no such execution context
[0-0]   (Session info: chrome=118.0.5993.70)
[0-0] 2023-11-15T20:23:41.769Z DEBUG webdriver: request failed due to response error: stale element reference
[0-0] 2023-11-15T20:23:41.769Z WARN webdriver: Request encountered a stale element - terminating request
[0-0] 2023-11-15T20:23:41.769Z INFO webdriver: COMMAND findElement("css selector", ".buy-now-btn")
[0-0] 2023-11-15T20:23:41.770Z INFO webdriver: [POST] http://0.0.0.0:55640/session/53e4f0d2a7876876adeadbcae4841f94/element
[0-0] 2023-11-15T20:23:41.770Z INFO webdriver: DATA { using: 'css selector', value: '.buy-now-btn' }
[0-0] 2023-11-15T20:23:41.847Z INFO webdriver: RESULT {
[0-0]   error: 'no such element',
[0-0]   message: 'no such element: Unable to locate element: {"method":"css selector","selector":".buy-now-btn"}\n' +
[0-0]     '  (Session info: chrome=118.0.5993.70)',

It happens for me on chrome browserVersion: ‘118’ webdriverio: ‘8.15.4’

Hi @ryan-cubic is this part The selector "" used with strategy "css selector" is invalid! a direct copy of the actual error? Because it seems really strange that the selector is empty. And If so, is #saveqatest the actually selector with which this happens? As I have never seen issues like this with the id selector or any other selector for that matter.