DEV Community

Discussion on: Advanced Automation Tips with Python | Selenium

Collapse
 
individualit profile image
Artur Neumann

"It is important to use time.sleep() if you are looping clicks. Because automation needs at least 2 seconds to perform another click. If you don't use time.sleep() then ElementClickInterceptedException error will appear."

In my experience there is no way to tell how long it will take to click and specially get a result of some sort. It depends on the app, on the computer the test runs on, on the browser and on the constellation of planets in the solar system.

Those sleeps will make your tests flaky (pass sometimes and break in other times), specially when running in CI on unknown hardware
same for stuff like:

bot.get('https://website.com/')
time.sleep(3)

You will better off to wait for the result of your action. Some waiting indicator disappearing, some specific field to appear that indicates that the side is loaded. Basically make a loop and wait for some event that would also indicate to the normal user that the site is ready for the next action