我已经通过xpath确定了一个问题,下面的内容与给定的HTML代码相同
XPath表达式
//a[@id='close_bttn']
文档
<form action="/gateway/orders" method="get">
<input class="dynamic-table-search-by" type="hidden" value="Date Range" name="searchBy"/>
<input type="hidden" value="20" name="pageSize"/>
<div class="input-prepend input-append">
<a id="close_bttn" class="btn dynamic-table-search-clear" href="/gateway/orders?pageSize=20&totalItems=16024" type="button">
<i class="icon-remove dynamic-table-search-clear-icon"/>
</a>
WebDriver运行后,我看到错误为
元素当前不可见,因此可能无法与命令持续时间或超时交互。
我看到没有为我正在处理的XPath添加隐藏标记。如果有任何解决方法,请告诉我。
答案 0 :(得分:1)
我猜你应该使用WebDriveWait:
WebDriverWait waiting = new WebDriverWait(driver, X, Y);
WebElement element = waiting.until(ExpectedConditions.visibilityOfElementLocated(By.id("close_bttn")));
此代码将在每Y毫秒内检查预期条件(close_bttn对象的可见性)。等待时间是X秒。
答案 1 :(得分:0)
以下是我如何使用双重检查,以确保:
public boolean isElementThere( By locator ) {
boolean found = false;
WebDriverWait waiting = new WebDriverWait(driver, 30, 2500);
WebElement element;
try {
element = waiting.until(
ExpectedConditions.visibilityOfElementLocated(locator));
element = waiting.until(
ExpectedConditions.presenceOfElementLocated(locator));
} catch ( WebDriverException e ) {
return false;
}
if ( element != null ) found = true;
return found;
}