WHAT IS THREAD.SLEEP() METHOD?

Thread.sleep() method is used to pause the for defined time. Time is defined in milliseconds for this method.

Here is the very basic program to use Thread.sleep() method in Selenium Webdriver script.




Java Source code:

package com.helloselenium.selenium.test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class OpenHelloSeleniumBlog{

 public static void main(String[] args) { 

  WebDriver driver = new FirefoxDriver();

  driver.get("http://helloselenium.blogspot.com");

  try{
   Thread.sleep(5000);
  }catch (InterruptedException ie1) {
    ie1.printStackTrace();
  } 
  
  driver.quit();
 }

}

Detailed explanation for the above program is as follows:




Following code is the required packages for Selenium Webdriver.
import org.openqa.selenium.WebDriver;
Following code is the required packages for Firefox browser.
import org.openqa.selenium.firefox.FirefoxDriver;
Above both required packages are available in downloaded selenium server jar file.
Following code is to initialize the Firefox driver.
WebDriver driver = new FirefoxDriver();
You can also use the following code is to open the hello selenium blog in browser.
driver.navigate().to("http://helloselenium.blogspot.com");




Following code is to open the hello selenium blog in browser.
driver.get("http://helloselenium.blogspot.com");
Following code is to pause the script for 5 seconds.
Thread.sleep(5000);
Following code is to quit the Firefox driver.
driver.quit();
You can also use the following code is to close the Firefox driver instance.
driver.close();



Post a Comment

1 Comments


What would you like to add in my list? I look forward to reading your comments below.