Click a button that is not yet on the screen

Asked

Viewed 113 times

1

I recently decided to do an automation using Python with the Selenium module. Everything was going well until I had to simulate a click on a button that is not on the screen at the moment and the time it appears varies with waiting time in the queue, I wanted to know how to make the webdriver wait for the button to appear so I could simulate the click... If anyone can help me, I’d be very grateful!

NOTE: I have tried this code: confirm = wait.until(EC.element_to_be_clickable((By.ID, "confirm"))) confirm.click(), but it didn’t work, always gives this error:

Traceback (Most recent call last): File "/home/lordvitor11/Desktop/Python/test.py", line 30, in confirm = Wait.until(EC.element_to_be_clickable((By.ID, "confirm")) File "/usr/local/lib/python3.8/dist-Packages/Selenium/webdriver/support/Wait.py", line 80, in until raise Timeoutexception(message, screen, stacktrace) Selenium.common.exceptions.Timeoutexception: Message:

1 answer

0


Try to make that code:

confirm = wait.until(EC.visibility_of_element_located((By.ID, "confirm"))) 
confirm.click()

probably your code didn’t work because your element "confirm" was not allocated, ie you were waiting for the element to become clickable when the element even existed on the page.

If that’s your problem you have some options:

To wait for the element to be allocated but not necessarily visible use

EC.presence_of_element_located()

To wait for the element to be allocated and visible use

EC.visibility_of_element_located()

The last option seemed more appropriate according to your question.

  • 1

    I used the code indicated and.... IT WORKED!! At first it was not working I read the error message and I realized that the time I put to wait was not being enough, so I increased the time and it worked!! Thank you very much!!! xD

Browser other questions tagged

You are not signed in. Login or sign up in order to post.