visibleOfElementLocated相对于visibleOfOf [英] visibilityOfElementLocated Vs visibilityOf

查看:669
本文介绍了visibleOfElementLocated相对于visibleOfOf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行以下代码时,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.

仅供参考,

  • 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屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆