Difference between isElementPresent and isVisible in Selenium RC

Harshavardhan Konakanchi picture Harshavardhan Konakanchi · Apr 19, 2012 · Viewed 22k times · Source

What is the difference between element isElementPresent and isVisible in Selenium RC. I get true for

selenium.isElementPresent() and selenium.isVisible()

If I get false for selenium.isElementPresent() I get Exception on selenium.isVisible()

Answer

Sachin Mhetre picture Sachin Mhetre · Apr 19, 2012

isElementPresent() - This method basically tests if the element we are looking for is present somewhere on the page.

isVisible() - looks for display: none style tag - this might throw a null pointer if we aren't careful...thus to see if an element is visible first check if the element is present using isElementPresent() method. Then try checking if the element is visible!

Observe that isElementPresent() won't mind even if our element is not visible.

For ex: lets say the below is the html code for a component on my test application:

now if you test the above component with

selenium.isElementPresent("testinput") - returns true!
selenium.isVisible("testinput") - returns false!