+2 votes
770 views
in Software Testing by (630 points)
i want to validate that elemets are avalable or not in my web page, how can i check ?
closed
0
by
We can also verify the elements are available or not on a web page in below ways:

Boolean isElementPresent;
Verification:1

WebDriver driver = new FirefoxDriver();
isElementPresent = driver.findElements(By.id("your_element_id")).size() > 0

Verification:2
try
{
driver.findElement(By.id("your_element_id"));
isElementPresent = true;
}
catch (NoSuchElementException e) {
isElementPresent = false;
}

1 Answer

+2 votes
by Expert (4.6k points)
selected by
 
Best answer

Its very simple : you can do like this :

 WebDriver driver = new FirefoxDriver();

 WebElement element1 = driver.findElement(By.id("id_of_1st_element"));

String Element1 = element1.toString();

System.out.println( Element1 +" is avalable");

WebElement element2 = driver.findElement(By.id("id_of_2st_element"));

String Element2 = element2.toString();

System.out.println( Element2 +" is avalable");

Enjoy!

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated