- Selenium:硒如何识别可见或不可见的元素?是否有可能它已加载到 DOM 中但未渲染到 UI 上?
我想验证元素可点击的场景,我知道网络驱动器有方法“ElementToBeClickable”,但是,我想知道内部工作原理。请帮我解决这个问题。
- 另外,如何处理元素已加载到 DOM 中但 UI 显示正在加载的情况,如何等待完全加载?
- 请告诉我,如果UI未加载,那么selenium会直接调用DOM元素,或者如果UI元素正在加载,那么它将执行失败?我真的很感激对此的更多技术解释。
-
Selenium可以识别presence or 能见度元素一旦存在present or visible in the HTML DOM。从用户的角度来看,您可以调用isDisplayed()上的方法网页元素检查是否符合预期网页元素 is 显示的或不。根据目前的实施情况Selenium可能无法区分loaded and rendered元素。这可点击元素中的方法预期条件类设置了检查元素是否存在的期望visible and enabled这样你就可以click it.
-
当。。。的时候元素已加载到 DOM 中,但 UI 显示正在进行加载你还得wait为了JavaScript and AJAX 调用完成页面加载,以便所有网页元素页面上变成可互动的。最多等待完成加载你可以设置pageLoadStrategy
to normal但可能仍需诱导WebDriver等待对于预期的网页元素成为present, visible, 可互动的 or 可点击的.
在这里您可以找到有关的详细讨论页面加载策略
- 当然如果 UI 未加载 Selenium可能无法与某些 DOM 元素交互。
Update
根据你的反问,这是一个不同的阶段网页元素以及各自的预期条件检查阶段:
-
Presence一个元素的 :
presenceOfElementLocated(By locator)
An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible.
-
能见度一个元素的 :
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.
-
元素为可点击 :
elementToBeClickable(By locator)
An expectation for checking an element is visible and enabled such that you can click it.
Note: 根据文档元素可点击 - 显示并启用.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)