Implementation of Wait in Selenium
1 Thread.sleep() : This is the way by which we can hold the execution of script for the predefined time
It is forcefully wait for the given time
2 Implicitely Wait
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));
The ImplicitWait will tell the webdriver to wait certain duration when trying to find the element, this will be useful when certain elements on the webpage will not be available immediately and needs some time to load.
This will work only with find element commands
3 pageLoadTimeout()
By this we can wait for a certain period of time to wait for a page to load.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
4 Wait for Element Present: By this we can wait until a element present or application state to be changes
WebDriverWait wait = new WebDriverWait(firef, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id=':gp']/div/div")));
It is forcefully wait for the given time
2 Implicitely Wait
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));
The ImplicitWait will tell the webdriver to wait certain duration when trying to find the element, this will be useful when certain elements on the webpage will not be available immediately and needs some time to load.
This will work only with find element commands
3 pageLoadTimeout()
By this we can wait for a certain period of time to wait for a page to load.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
4 Wait for Element Present: By this we can wait until a element present or application state to be changes
WebDriverWait wait = new WebDriverWait(firef, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id=':gp']/div/div")));
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment