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
145 views
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;
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
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");

Enjoy!

Related Questions

+2 votes
1 answer 135 views
+2 votes
1 answer 1,270 views
+1 vote
1 answer 72 views
+1 vote
1 answer 2,250 views
+1 vote
1 answer 547 views
+5 votes
7 answers 14,605 views
+2 votes
2 answers 822 views
+11 votes
1 answer 124 views

Not a Member yet?

Ask to Folks Login

My Account
749 Folks are online
60 members and 689 guest online
Your feedback is highly appreciated