After submitting a POST request with a button click from a webpage, I want to wait for 60 seconds and click a link on that same page.

The wait for 60 seconds part, is that possible to implement with any keyword from robot selenium2library?

  • you can define directly 60 seconds wait in code. No need to press any keyword for wait. Commented Feb 24, 2015 at 6:46
  • Thanks @HelpingHands. I did exactly what you said. There is no keyword in robot selenium 2 library I found, which helps me wait for a random time. So, I implemented a keyword 'Wait For timeout'. def wait_for(self, timeout): timeout = robot.utils.timestr_to_secs(timeout) maxtime = time.time() + timeout while True: if time.time() > maxtime: break time.sleep(0.2) Commented Feb 24, 2015 at 7:51
  • Great..cheers... Commented Feb 24, 2015 at 7:52
  • Your title says "random time" but your question specifically mentions 60 seconds. Are you wanting a keyword that can wait a random amount of time (eg: "wait 0-60 seconds"), or one that can wait on a specific amount of time given by the test case? Commented Feb 24, 2015 at 12:13
  • Why do you want to wait? Most of the time sleeping is not the solution during automated tests, better to wait for the effect to happen. Actions that have no visible effects... Commented Feb 24, 2015 at 12:15

4 Answers 4


Putting a sleep in a selenium test is generally not the best solution. Selenium has keywords to wait for some condition on a page, such as wait for condition, wait until element is visible, wait until page contains, and wait until page contains element. These are preferable, since the wait will usually be as short as possible. With a fixed-time wait, you may be waiting considerably longer than necessary, or you may not be waiting long enough.

However, since you asked specifically about sleeping, the robot framework BuiltIn library has a sleep keyword. The time format it uses is described in the robot framework users guide.

sleep | time | reason=none

Pauses the test executed for the given time.

time may be either a number or a time string. Time strings are in a format such as '1 day 2 hours 3 minutes 4 seconds 5milliseconds' or '1d 2h 3m 4s 5ms', and they are fully explained in an appendix of Robot Framework User Guide. Optional reason can be used to explain why sleeping is necessary. Both the time slept and the reason are logged.


You mention in the comments:

What happens in my application is, after POSTing something, it takes sometime to update everything(indexing involved), for that specific reason we need to wait sometime and refresh the page, otherwise if I use wait for condition/wait until element is visible/wait until page contains/wait until page contains element , I cannot refresh the page when any of those keywords wait for the expected element and hence it will definitely fail.

You can define a custom wait action that will do exactly what you want, something like:

    Wait<WebDriver> wait = new FluentWait<WebDriver>( driver )
                .withTimeout(60, TimeUnit.SECONDS);

    wait.until( new ExpectedCondition<Boolean>() { 
        public Boolean apply( WebDriver webDriver ) {
            //Check for data here. Return true if the data is what you want it to be
      } );

The advantage to doing this is that if it takes less than 60 seconds, you will exit early, making your test faster.


Following code should be added to robot selenium2 library in order to use this keyword: Wait For | timeout

def wait_for(self, timeout):
    timeout = robot.utils.timestr_to_secs(timeout)
    maxtime = time.time() + timeout
    while True:
        if time.time() > maxtime:

In case you neeed to WAIT A RANDOM TIME, I just achieved that with this (in my case between 1 and 3 seconds):

Library       random

${randomWait}=    Evaluate    random.randint(1,3)    random
Sleep    ${randomWait}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.