
我想看看数字65692后面有没有'+‘号。
我试过了:
driver.findElement(By.id(activeResource + "Current_Works_Order")).findElements(By.className("fa fa-plus multipleOpsIcon"));即使没有'+‘,这也会返回一个列表。
搜索此元素的最佳方法是什么?
发布于 2020-01-31 21:46:17
如果你不想接收一个列表,并且只想接收一个元素,你应该使用"findElement“而不是"findElements”。
在我看来,您查找子元素的方法是有效的。
我用来检查元素是否存在的方法是:
public static boolean checkElement(By by) {
try {
if (!isPresent(by)) {
return false;
}
if (!isVisible(by)) {
return false;
}
return true;
} catch (StaleElementReferenceException e) {
e.printStackTrace();
return false;
} catch (Exception e) {
return false;
}
}
public static boolean isPresent(By by) {
try {
getElement(by).getLocation();
return true;
} catch (StaleElementReferenceException e) {
e.printStackTrace();
return false;
} catch (Exception e) {
return false;
}
}
public static boolean isVisible(By by) {
try {
return getElement(by).isDisplayed();
} catch (StaleElementReferenceException e) {
e.printStackTrace();
return false;
} catch (Exception e) {
return false;
}
}
public static WebElement getElement(By by) {
try {
return driver.findElement(by);
} catch (StaleElementReferenceException e) {
e.printStackTrace();
return null;
} catch (Exception e) {
return null;
}
}希望能有所帮助。
https://stackoverflow.com/questions/60003185
复制相似问题