Alternative Approach to Solve Thread.Sleep in Java or Selenium or in OpenScript

Share and Enjoy !

Thread.Sleep in Java

Now a days if we want our execution to be halted for sometimes [mainly observed in Automation Testing when a page needs to be loaded first and then some line of code will be executed], We use Thread.sleep(int Sec) method. Well this is quite recognized/common method to solve if we want my program to wait for specific point of time.More details can be found here in java doc.
As per java doc..

Notice that main declares that it throws InterruptedException. This is an exception that sleep throws when another thread interrupts the current thread while sleep is active. Since this application has not defined another thread to cause the interrupt, it doesn’t bother to catch InterruptedException.

But now a days I have seen that it is a requirement to do more customization regarding the same.
One approach can be –[taken from stackoverflow]

public static void pause(int seconds){
     Date start = new Date();
     Date end = new Date();
     while(end.getTime() - start.getTime() < seconds * 1000){
         end = new Date();

Another Approach can be to use.

Pause.pause(int sec)

The third approach can be..

public static void wait_for_element(){
      pause(2);//use the first approach for implementing this pause method
//the element is displayed


Thread.Sleep in Java

Now the choice is yours …depending on the scenario, you can take any one of the process. Happy testing.

Share and Enjoy !

12 thoughts on “Alternative Approach to Solve Thread.Sleep in Java or Selenium or in OpenScript

  1. Feelings were great to visit dis….. Bt thr is a problem at d tym of subscription (smthng email problem).

  2. Hello Abhranil,
    you can join via this link-

  3. My brother recommended I may like this website. He was entirely right.

    This post actually made my day. You can not
    consider just how so much time I had spent for this information! Thank you!

  4. What’s up all, here every one is sharing such familiarity, thus
    it’s fastidious to read this webpage, and I used to go to
    see this weblog all the time.

  5. Wow, this piece of writing is fastidious, my younger sister is analyzing these kinds of things,
    therefore I am going to let know her.

  6. I don’t even know how I ended up here, but I thought this post was great.
    I do not know who you are but definitely you’re going to a famous blogger
    if you aren’t already 😉 Cheers!

  7. Pingback: Google
  8. Pingback: Google
  9. Pingback: Google

Leave a Reply

Your email address will not be published. Required fields are marked *