我无法使用WebDriverWait查找某个Web元素,该Web元素返回未找到的元素
WebElement e = findElementByCondition(5,new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("id"));
}
});
public WebElement findElementByCondition(int timeOut, ExpectedCondition<WebElement> condition)
{
WebElement el = null;
try
{
el = new WebDriverWait(mUser.mDriver, timeOut)
.ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class)
.ignoring(ClassCastException.class)
.ignoring(NullPointerException.class)
.until(condition);
}
catch (TimeoutException e)
{
Log.d(TAG,"TimeoutException()");
}
return el;
}
但是我可以直接使用驱动程序找到网络元素
WebElement e = driver.findElement(By.id("id"));
我的代码不正确吗?
答案 0 :(得分:0)
问题是我是根据找到的第一个元素从WebDriverWait返回的,而不是使用整个列表,例如
@Override
public Boolean apply(WebDriver driver) {
Print.tag("apply()");
List<WebElement> els = driver.findElements(By.className(CLASS_TEXT_VIEW));
for(WebElement el : els)
{
if(el.getText().contains(desiredText))
{
Log.d(TAG,"found match");
return true;
}
}
Log.d(TAG,"no match found");
return false;
}