When i tried to run below code, visibilityOfElementLocated
works perfectly fine and webdriver waits for the element with given time.
dr.get("http://www.seleniumframework.com/Practiceform/");
WebDriverWait wait=new WebDriverWait(dr,30);
WebElement we = wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Element5")));
but the same way if i use visibilityOf
, it gives me
NoSuchElementException
WebElement we = wait.until(ExpectedConditions.visibilityOf(dr.findElement(By.linkText("Element3"))));
Can you explain me why i am getting this exception?
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 uses By
object instead of WebElement
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With