0 votes
1 view
in Python by (32.3k points)

I don't want to change the implicit wait for the WebDriver, because this problem happens only on a particular click.

Please Note: There is no code executed after the click statement. This isn't the usual wait failure. I tried adding a simple "print("test") after the driver.find_element_by_xpath(xpath).click() but execution fails at the click itself. The print is not executed. Webdriver times out while waiting for the page to load (upwards of 5 minutes).

I need to submit a particular form. This form takes a lot of time after clicking on the submit button. It can take up to 5 minutes to load the next page.

WebDriver times out after clicking this button with a "TimeOut" exception.

Here is the stack trace:

Traceback (most recent call last):

File "C:/Users/user.domain/PycharmProjects/server_config/server_config.py", line 704, in # Apply the reset File "C:/Users/user.domain/PycharmProjects/server_config/server_config.py", line 222, in server_reset logger.info("Resetting the server config") File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 501, in _execute return self._parent.execute(command, params) File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute self.error_handler.check_response(response) File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: timeout (Session info: chrome=75.0.3770.100) (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/[email protected]{#29}),platform=Windows NT 10.0.17763 x86_64)

Sometimes the page errors out and doesn't even show the landing page. On other occasions, it takes 5 minutes or even more.

How can I handle this particular click? What is a more elegant way to handle the wait request instead of changing the implicit wait values before and after this click?

1 Answer

0 votes
by (16.8k points)

implicit wait doesn't effect the page load, it's only relevant to locating web elements with find_element() functions.

You can use driver.set_page_load_timeout(timeout) to increase the time the driver awaits the page to load (although according to the w3c specification the default value is already 5 minutes).

In case the page doesn't load at all you can use try except if you wish to do something else than terminating with exception



except TimeoutException:

    print('Failed to load next page')

    # do something

    # or rethrow the exception with 'raise'

Welcome to Intellipaat Community. Get your technical queries answered by top developers !