Thursday, July 28, 2011

isElementPresent in Selenium-2.0

While going through Selenium-2.0 I found out that WebDriver does not have a function called isElementPresent(). This was one of the important functions that was used in Selenium-1.0. It was mainly used for waiting for an element to be available to take an action on it. To implement this in WebDriver you just need to write a method as mentioned below. You can then  use this function with any type of "By"(By.id, BY.name, etc.)



The above function will return true in case the element is found on the page, else it will return false. 
In case your want to wait for a element to be present you can implement it in the following way.

2 comments :

Priya said...

Hi Varun, Can you please explain about the page object model. Thank you.

Varun Menon said...

Hopefully the following link helps.

http://code.google.com/p/selenium/wiki/PageObjects

The basic funda is you have a class for each page in your app. These classes define particular scenario/use-cases and once successful return another page class object wither of iteself or of another depending whether the scenario/use-case involve any page navigation.

Post a Comment