Hey there! any question in your mind? Ask It Now!.

Popular Categories

Can i check, Elements are available on a web page or not in selenium Web driver?

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

Boolean isElementPresent;

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

isElementPresent = true;
catch (NoSuchElementException e) {
isElementPresent = false;

1 Answer

+2 votes
answered by seleniumGuru Expert (4,570 points)
selected by ramesh
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");


Related Questions

+1 vote
1 answer 698 views

Not a Member yet?

Ask to Folks Login

My Account
316 Folks are online
3 members and 313 guest online
Your feedback is highly appreciated