visibleOfElementLocated相对于visibleOfOf [英] visibilityOfElementLocated Vs visibilityOf
问题描述
当我尝试运行以下代码时,visibilityOfElementLocated
可以很好地工作,并且webdriver在给定的时间等待该元素.
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")));
但如果我使用visibilityOf
的方式相同,它会给我
but the same way if i use visibilityOf
, it gives me
NoSuchElementException
NoSuchElementException
WebElement we = wait.until(ExpectedConditions.visibilityOf(dr.findElement(By.linkText("Element3"))));
您能解释一下为什么我会收到这个例外吗?
Can you explain me why i am getting this exception?
推荐答案
但是如果我使用"visibilityOf",它也会以同样的方式给我NoSuchElementException
but the same way if i use "visibilityOf",it gives me NoSuchElementException
实际上,您通过此行代码 dr.findElement(By.linkText("Element3"))
获得Exception
,在您提供的代码中,该行将首先执行,如果先找到element,然后再
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.
仅供参考, WebElement
.
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.
这篇关于visibleOfElementLocated相对于visibleOfOf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!