Difference between isElementPresent and isVisible in Selenium RC

What is the difference between isElementPresent and isVisible in Selenium RC. I believe in

selenium.isElementPresent() and selenium.isVisible()

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

+8
java selenium selenium-rc
source share
2 answers

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

isVisible () - looks for a display: there is no style tag - this can cause a null pointer if we are not careful ... so that to see if an element is visible, first check if the element is present using the isElementPresent () method. Then try to check if the item is visible!

Please note that isElementPresent () will not mind even if our item is not displayed.

For example: let's say below: the html code for the component in my test application:

now if you test the above component with

 selenium.isElementPresent("testinput") - returns true! selenium.isVisible("testinput") - returns false! 
+19
source share

How about reading the documentation ?

boolean isElementPresent (locator java.lang.String)

Verifies that the specified item is somewhere on the page.

boolean isVisible (locator java.lang.String)

Determines whether the specified item is visible. An element can be rendered invisible, setting the CSS visibility property to hidden or display the none property, either for the element itself or for one, if its ancestors. This method will not work if the item is not.

+11
source share

All Articles