Sometimes you need selenium wait until element is visible when your targeted element is not visible on the page when the page is loading. If you can put something like wait until element is visible selenium java test then test execution will wait until the condition match. In any software web application's webdriver test case, you can easily wait for the presence of an element using IMPLICIT WAIT. If you have used implicit wait in your test case then you do not require to write any extra conditional statement to wait for element visibility. But in some cases, if any element is taking too much time to be visible on the software web page then you can use EXPLICIT WAIT condition in your test case.
wait until element is visible selenium java
If you have a scenario of selenium wait for element to be visible on the software web page then selenium webdriver/Selenium 2 has its own method named visibilityOfElementLocated(By locator) to check the visibility of an element on the software web page. We can use this method with explicit webdriver wait condition to selenium wait element visible on the page. However, we can wait for an element to be clickable using elementToBeClickable(By locator) method as described in THIS ARTICLE.
Syntax to wait until element is visible selenium java on page is as bellow. It will wait max 15 seconds for element. As soon as element visible on page, webdriver will go for executing next statement.
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='text3']")));
Here is a practical example of waiting until the element is visible selenium java. Execute it once and then use it for your software web application test scenario.
Copy below the given @Test method part of the wait for visibility of the element located example and replace it with the @Test method part of the example given on THIS PAGE. (Note: @Test method is marked with pink color in that linked page).
Example of wait until element is visible selenium java
@Test
public void test () throws InterruptedException, IOException
{
//To wait for element visible
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='text3']")));
driver.findElement(By.xpath("//input[@id='text3']")).sendKeys("Text box is visible now");
System.out.print("Text box text3 is now visible");
}
No comments:
Post a Comment