visibilityOfElementLocated Vs visibilityOf
but the same way if i use "visibilityOf",it gives me NoSuchElementException
Actually, you are getting Exception
by this line of code dr.findElement(By.linkText("Element3"))
, in your provided code this line will execute first and if element will be find then ExpectedConditions.visibilityOf()
callable will execute.
FYI, WebDriver.findElement()
either throws exception or returns a WebElement
.
visibilityOfElementLocated
Vs visibilityOf
:-
visibilityOfElementLocated
is used for checking that an element is present on the DOM of a page and visible. Means it usesBy
object instead ofWebElement
object with callable function to find that element first then check that element is visible or not.visibilityOf
is used for checking that an element, known to be present on the DOM of a page, is visible. Means you have already found that element and just check only for that visibility.
According to this:
visibilityOf: Does not check for presence of the element as the error explains it.
visibilityOfElementLocated: Checks to see if the element is present and also visible. To check visibility, it makes sure that the element has a height and width greater than 0.