use*_*625 5 html selenium-webdriver
我正在编写脚本来选择并在JIRA的下面的屏幕中输入值.
<input type="text" autocomplete="off" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" class="text aui-ss-field ajs-dirty-warning-exempt" id="issuetype-field" aria-controls="issuetype-suggestions">Run Code Online (Sandbox Code Playgroud)
在输入"输入类型"的值后,其他字段(如"摘要")将灰显几秒钟.如果我尝试输入'summary'字段的值,请使用以下代码:
myDriver.findElement(By.id("summary")).sendKeys(summary);
Run Code Online (Sandbox Code Playgroud)
将不会输入摘要字段,而是会出现错误"在缓存中找不到元素 - 可能页面自查找以来已更改...".
"摘要"字段的HTML代码是:
<input type="text" value="" name="summary" id="summary" class="text long-field">Run Code Online (Sandbox Code Playgroud)
所以我想要的只是等待'summary'输入字段被启用然后sendkey到它.我正在寻找类似的东西
ExpectedConditions.presenceOfElementLocated
Run Code Online (Sandbox Code Playgroud)
但相反,我希望' 启用 ',而不是presenceOfElementLocated或visibilityOfElementLocated.我不想用Thread.sleep().
有什么建议?
怎么样ExpectedConditions.elementToBeClickable(locator)?
elementToBeClickable 检查元素是否已启用.
public void waitForElementEnabled(final WebElement element) {
try {
getWait().until((ExpectedCondition<Boolean>) driver -> element.isEnabled());
} catch (Exception e) {
LOGGER.info(
e + " : " + "Timed out waiting for element: " + element);
}
}
Run Code Online (Sandbox Code Playgroud)
等待是一个 WebDriverWait,我们希望等到启用 WebElement 时获得真正的响应。驱动程序是我的 WebDriver 实例,它是全局声明的。如果它超时而没有得到真正的响应,那么我可以取消异常(以便测试将继续)并显示一条消息,通知操作超时。我使用的是 Lambda 表达式,因此您需要使用 selenium 3.1 或更高版本(使用 guava 21)
| 归档时间: |
|
| 查看次数: |
15136 次 |
| 最近记录: |