Sun*_*nil 4 selenium dom selenium-webdriver webdriverwait expected-condition
一旦元素在HTML DOM中出现或可见, Selenium就可以识别它们的存在或可见性。从用户角度来看,您可以调用WebElement上的方法来检查是否显示预期的WebElement。根据当前的实现,Selenium可能无法区分加载的元素和渲染的元素。ExpectedConditions类中的ElementToBeClickable方法设置一个期望,用于检查元素是否可见并启用,以便您可以单击它。isDisplayed()
当元素加载到 DOM 中但 UI 显示加载正在进行时,您仍然需要等待JavaScript和AJAX 调用来完成页面加载,以便页面上的所有WebElement都变得可交互。最多等待完全加载,您可以将 设为正常,但可能仍然需要引发WebDriverWait以使预期的WebElement变得存在、可见、可交互或可点击。pageLoadStrategy
在这里您可以找到有关页面加载策略的详细讨论
根据您的反问题,这里是WebElement的不同阶段以及检查阶段的相应ExpectedConditions :
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.
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
可点击的元素:
elementToBeClickable(By locator)
An expectation for checking an element is visible and enabled such that you can click it.
Run Code Online (Sandbox Code Playgroud)
注意:根据文档,元素是可点击的 - 它已显示并启用。