DEV Community

Cover image for Selenium Python Wait Commands
Dilpreet Johal
Dilpreet Johal

Posted on

Selenium Python Wait Commands

In this post, we will learn about the various wait commands available in Selenium Python using the SeleniumBase framework. Using wait commands when doing browser automation is inevitable. Therefore, it’s important to understand how to use wait commands the right way.

Using “Wait” the Wrong way

Now, this one, in particular, is a pet-peeve of mine. I have seen time and again in many codebases where hard-coded sleeps are used instead of implementing the right wait commands. I am sure you have seen this before as well or a variation of the code below –


While this one line in a single test won’t do much harm but just imagine when this becomes the “norm” for most of your tests. Soon, you will find your test run time to double, triple, or even quadruple * gulps * due to that 1 harmless line.

Using “Wait” conditionally

Now that we know using hard-coded sleep is a bad practice, what can we do when we still need to use wait in our tests? Well, you would still use wait commands but this time you will wait for a particular condition to complete.

For example, if you need to wait for an element to be visible on the screen so that you can perform your next step, you could do something like this –


In the sample code above, I am not explicitly telling my test to wait ‘x’ amount of seconds before performing the next step. Rather, I am using a max timeout (6 seconds set in config) for my element to be visible on the screen. This way, my element can appear on the screen in 2 secs or 4 seconds, and then it will move on to the next steps saving you a couple of extra seconds!

Some other wait commands to use –


Check out the video below to learn more about the wait commands in Selenium Python –

To learn more about Selenium Python, check out the full tutorial series here for free!

📧 Subscribe to my mailing list to get access to more content like this

👍 Follow automationbro on Twitter for the latest updates


I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -

Buy me a coffee

You can also support me by liking and sharing this content.

Thanks for reading!

Discussion (0)