SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.23k stars 8.12k forks source link

[šŸ› Bug]: NoSuchElementException not thrown when using implicitly_wait in BrowserStack #14525

Open silvadf9 opened 2 hours ago

silvadf9 commented 2 hours ago

What happened?

Issue

While executing tests on a remote driver (BrowserStack), when the method _find_element()_ doesn't find the element instead of throwing the NoSuchElementException it is returning the dict with the error.

This causes issues, for example, on the ExpectedConditions library which isn't expecting a dict as the response and generates a AttributeError: 'dict' object has no attribute 'is_displayed'

Possible cause

I've been doing some investigation and I think the issue is that the response sent to the remote/ErrorHandler.check_response() method doesn't contain a "status" field, e.g.:

response = {'value': {'error': 'no such element', 'message': 'no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(text(), \'SET DISPOSITION\')]/.. | //button[contains(text(), \'Set Disposition\')]"}\n (Session info: chrome=128.0.6613.85)', 'stacktrace': '\tGetHandleVerifier [0x00007FF61A05B632 29090]\n\t(No symbol) [0x00007FF619FCE6E9]\n\t(No symbol) [0x00007FF619E8B1CA]\n\t(No...No symbol) [0x00007FF619FC4A7F]\n\tBaseThreadInitThunk [0x00007FFC08C3257D 29]\n\tRtlUserThreadStart [0x00007FFC0990AA78 40]\n'}}

As far as I can tell, the issue is only happening on the remote webdriver after setting an implicitly_wait > 1.

How can we reproduce the issue?

Example code:

    options = webdriver.ChromeOptions()
    driver = webdriver.Remote(command_executor=server, options=options)
    driver.implicitly_wait(30)
    driver.find_element(By.XPATH, value="Non-Existing Element")

Relevant log output

>               modal = self.driver.find_element(By.XPATH, "Modal_XPATH")
>               if modal.is_displayed():
E               AttributeError: 'dict' object has no attribute 'is_displayed'

../../SOMETHING/SOMETHING.py:174: AttributeError

Operating System

Windows 11

Selenium version

Python 4.19.0

What are the browser(s) and version(s) where you see this issue?

Chrome 128

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 128.0.6613.137

Are you using Selenium Grid?

No

github-actions[bot] commented 2 hours ago

@silvadf9, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!