SeleniumHQ / selenium

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

[πŸ› Bug]: WebDriverWait of latest Selenium version: 4.25.0 with Python 3.12 is throwing selenium.common.exceptions.TimeoutException: Message: #14570

Open manikandanma17 opened 1 day ago

manikandanma17 commented 1 day ago

What happened?

I tried to run my python selenium script today contains WebDriverWait class imported as follows and observed below Timeout exception. Please refer to Relevant log output section for error logs.

Example: from selenium.webdriver.support.ui import WebDriverWait

element = WebDriverWait(browser, 10).until(
    EC.element_to_be_clickable((By.XPATH, '/html/body/div/div[2]/div/div[3]/div/form/input[2]'))
)
browser.execute_script('arguments[0].click();', element)

NOTE: The same python selenium script was working fine till last friday (4th Oct 2024) when I had SELENIUM 4.24.0 installed in mac system. Today i started seeing this issue, then when I investigated further, i observed that Selenium latest version 4.25.0 was installed in my system. Then I uninstalled SELENIUM 4.25.0 and reinstalled SELENIUM 4.24.0 in my system and found that my same python selenium scripts are started working fine now.

How can we reproduce the issue?

Just add WebDriverWait statement for any WebElement to be identified and run the .python script, you will observe Timeout exception.

Example: 
from selenium.webdriver.support.ui import WebDriverWait

    element = WebDriverWait(browser, 10).until(
        EC.element_to_be_clickable((By.XPATH, '/html/body/div/div[2]/div/div[3]/div/form/input[2]'))
    )
    browser.execute_script('arguments[0].click();', element)

Relevant log output

I ran below CLI in pycharm IDE:

pytest generated_tests/test.py

Logs snippet:

fixturefunc = <function enter_service_into_username_field at 0x1054fe160>, request = <FixtureRequest for <Function test_login>>
kwargs = {'browser': <selenium.webdriver.chrome.webdriver.WebDriver (session="c588657992fd1ce9cec2495e13b6c354")>}

    def call_fixture_func(
        fixturefunc: _FixtureFunc[FixtureValue], request: FixtureRequest, kwargs
    ) -> FixtureValue:
        if is_generator(fixturefunc):
            fixturefunc = cast(
                Callable[..., Generator[FixtureValue, None, None]], fixturefunc
            )
            generator = fixturefunc(**kwargs)
            try:
                fixture_result = next(generator)
            except StopIteration:
                raise ValueError(f"{request.fixturename} did not yield a value") from None
            finalizer = functools.partial(_teardown_yield_fixture, fixturefunc, generator)
            request.addfinalizer(finalizer)
        else:
            fixturefunc = cast(Callable[..., FixtureValue], fixturefunc)
>           fixture_result = fixturefunc(**kwargs)

.venv/lib/python3.12/site-packages/_pytest/fixtures.py:898: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
generated_tests/login.py:35: in enter_service_into_username_field
    element = WebDriverWait(browser, 10).until(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.support.wait.WebDriverWait (session="c588657992fd1ce9cec2495e13b6c354")>, method = <function visibility_of_element_located.<locals>._predicate at 0x105329e40>, message = ''

    def until(self, method: Callable[[D], Union[Literal[False], T]], message: str = "") -> T:
        """Calls the method provided with the driver as an argument until the \
        return value does not evaluate to ``False``.

        :param method: callable(WebDriver)
        :param message: optional message for :exc:`TimeoutException`
        :returns: the result of the last call to `method`
        :raises: :exc:`selenium.common.exceptions.TimeoutException` if timeout occurs
        """
        screen = None
        stacktrace = None

        end_time = time.monotonic() + self._timeout
        while True:
            try:
                value = method(self._driver)
                if value:
                    return value
            except self._ignored_exceptions as exc:
                screen = getattr(exc, "screen", None)
                stacktrace = getattr(exc, "stacktrace", None)
            time.sleep(self._poll)
            if time.monotonic() > end_time:
                break
>       raise TimeoutException(message, screen, stacktrace)
E       selenium.common.exceptions.TimeoutException: Message:

.venv/lib/python3.12/site-packages/selenium/webdriver/support/wait.py:105: TimeoutException
============================================================================================= short test summary info =============================================================================================
FAILED generated_tests/login.py::test_login - selenium.common.exceptions.TimeoutException: Message:
=============================================================================================== 1 failed in 14.44s ================================================================================================
(.venv) manikandanm ~/Test  $ pytest ./generated_tests/login.py

Operating System

Mac Ventura 13.5.1

Selenium version

Python 3.12

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

Chrome, Version 129.0.6668.90

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

Selenium 4.25.0

Are you using Selenium Grid?

No

github-actions[bot] commented 1 day ago

@manikandanma17, 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!

navin772 commented 1 day ago

Hi @manikandanma17 I tried to reproduce the error with selenium 4.25 but couldn't, here is the minimal python script I used, can you see if this works on your setup?

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service

chrome_service = Service('/Users/navinchandra/Downloads/chromedriver-mac-x64/chromedriver') # replace with your chromedriver path

browser = webdriver.Chrome(service=chrome_service)

browser.get('https://www.google.com')

element = WebDriverWait(browser, 3).until(
    EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/textarea'))
)
browser.execute_script('arguments[0].click();', element)

browser.quit()

I have tried this with both python 3.11 and 3.12 and it works.

Also, check if the XPATH is valid in your case since you are getting the TimeoutException.

Any additional info would be helpful.