[英]isDisplayed() method always returns true for some elements
I'm using Selenium to test appearance of error message when input field is empty. 输入字段为空时,我正在使用Selenium测试错误消息的外观。 Error message designed as a label to input element.
错误消息设计为输入元素的标签。 When the message is invisible, it has attribute "display: none;"
当消息不可见时,它具有属性“ display:none;”。 .
。
When I find that message by text and call isDisplayed() method, it always returns true, even when message is invisible. 当我通过文本找到该消息并调用isDisplayed()方法时,即使消息不可见,它也始终返回true。 I write tests on Java, so I have no isVisible() message.
我在Java上编写测试,所以没有isVisible()消息。
I've tried method getAttribute("style") , but it returns empty string. 我试过了getAttribute(“ style”)方法 ,但是它返回空字符串。 Method getCssValue("display") returns "block" even when on page it has value "none" .
方法getCssValue(“ display”)即使在页面上具有值“ none”时也返回“ block ” 。
I expected ElementNotVisibleException after calling click() method, but nothing happened! 调用click()方法后,我期望ElementNotVisibleException ,但没有任何反应!
Any ideas? 有任何想法吗? Workarounds?
解决方法?
Here example of HTML: 以下是HTML的示例:
<form id="from id" style="display: block;">
<input id="input" name="input">
<label for="input" generated="true" style="display: none;">Error text here.</label>
</from>
Try using a WebDriverWait() to find the WebElement, and you can wait for the visibility of the element: 尝试使用WebDriverWait()查找WebElement,然后可以等待元素的可见性:
/**
*
* Get a Web Element using WebDriverWait()
*
*/
public WebElement getInputBox() throws TimeoutException {
WebElement webElement = null;
WebDriverWait driverWait = new WebDriverWait(5);
// find an element using a By selector
driverWait.until(
ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#input")));
webElement = driver.findElement(By.cssSelector("#input"));
return webElement;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.