为什么有些元素存在但不能交互/显示? [英] Why do some elements exist but not interactable/displayed?
问题描述
我对测试还很陌生,试图更好地了解到底发生了什么.我发现当css选择器元素附加了waitUntilCanInteract或waitUntilDisplayed时,我们的某些测试代码失败了,即使我执行Chrome检查该元素是否显示在浏览器中时也是如此.将它们更改为waitUntilExists会使它们达到一个传递点,所以我想知道到底是什么情况造成了这种情况?
I'm pretty new to testing, trying to gain a better understanding of what exactly is going on. I'm finding some of our test codes are failing when the css selector element has a waitUntilCanInteract or waitUntilDisplayed attached to it even though when I do a chrome inspect the element is showing up in the browser. Changing them to a waitUntilExists gets them to a passing point so I was wondering what exactly is going on to create this situation?
推荐答案
Precisesly Selenium deals with three unique states of an element.
Presence of element within the html: This state of an element can be detected through the ExpectedCondition
presenceOfElementLocated()
where the expectation is to check if the element is present in the DOM of a page. This does not necessarily mean that the element is visible.
-
示例:
Exmaple:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("css_of_element")));
元素可见性>:可以通过 ExpectedCondition DOM 中显示为显示,并可见.可见性表示该元素不仅会显示,而且其 height 和 width 会大于 0 .
Visibility of element within the html: This state of an element can be detected through the ExpectedCondition visibilityOfElementLocated()
where the expectation is to check if the element is present in the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0.
-
示例:
Exmaple:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("css_of_element")));
Element to be clickable: This state of an element can be detected through the ExpectedCondition elementToBeClickable()
where the expectation is to check if the element visible and enabled so that you can click it.
-
示例:
Exmaple:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("css_of_element")));
这篇关于为什么有些元素存在但不能交互/显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!