Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the exact difference between "ExpectedConditions.visibilityOfElementLocated" and "ExpectedConditions.presenceOfElementLocated"

My apologies in advance if my question sounds primary, I am very new at QA and Selenium.

What is the exact difference between:

 wait.until(ExpectedConditions.visibilityOfElementLocated
                    (By.xpath("//a[text()='Show advanced settings...']"))).click();

and

 wait.until(ExpectedConditions.presenceOfElementLocated
                    (By.xpath("//a[text()='Show advanced settings...']"))).click();

I had a look at here but did not figure it out.

like image 943
LoveLovelyJava Avatar asked Oct 20 '15 17:10

LoveLovelyJava


People also ask

What is the difference between presenceOfElementLocated and visibilityOfElementLocated?

use presenceOfElementLocated when you don't care whether if element visible or not, you just need to know if it's on the page. use visibilityOfElementLocated when you need to find element which should be also visible.

What is ExpectedConditions in explicit Wait Is it a class or interface?

In order to declare explicit wait, one has to use “ExpectedConditions”. The following Expected Conditions can be used in Explicit Wait. To use Explicit Wait in test scripts, import the following packages into the script. Then, Initialize A Wait Object using WebDriverWait Class.

What is Selenium ExpectedConditions?

Expected Conditions in Selenium WebDriver provide conditions that are frequently used for automating test scenarios for Selenium automation testing. Like other Selenium language bindings, Expected Conditions in Java provide ways through which you can realize Explicit Waits in the test code.

How you will identify invisibility of a WebElement?

We can also confirm if an element is visible with the help of isDisplayed() method. This method returns a true or a false value. In case the element is invisible, the method returns a false value.


1 Answers

The visibilityOfElmementLocated checks to see if the element is present and also visible. To check visibility it makes sure the element has a height and width greater than 0.

The presenceOfElementLocated just checks the dom to see if it can locate an element no matter its visibility.

Source: https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#visibilityOf-org.openqa.selenium.WebElement-

visibilityOf public static ExpectedCondition visibilityOf(WebElement element) An expectation for checking that an element, known to be present on the DOM of a page, is visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0. Parameters:

like image 64
Joseph Cox Avatar answered Sep 20 '22 21:09

Joseph Cox