在Firefox上使用Inspect Element,并复制CSS Selector,我得到以下内容:
div.GBNJJH1BCUB:nth-child(3) > input:nth-child(1)
我已在我的页面类中声明:
private static final String logoutButtonCss="div.GBNJJH1BBUB:nth-child(3) > input:nth-child(1)";
这是找到这个元素的正确方法吗?
@FindBy(css=logoutButtonCss) private WebElement logoutButton;
byExpression允许我使用Css Selector:
By byExpression = By.cssSelector(logoutButtonCss);
我在这里使用后者:
public static boolean isWebElementPresent(By byExpression, WebDriver driver) {
WebDriverWait wait = new WebDriverWait(driver, Constant.timeOut);
try {
wait.until(ExpectedConditions.presenceOfElementLocated(byExpression));
return true;
} catch (TimeoutException e) {
LOGGER = Logger.getLogger(Common.class.getName());
LOGGER.setLevel(Level.INFO);
LOGGER.warning("Timeout searching for " + byExpression);
return false;
}
}
答案 0 :(得分:-2)
@FindBy注释需要文字文本,而不是变量:
@FindBy(css="div.GBNJJH1BBUB:nth-child(3) > input:nth-child(1)")
private WebElement logoutButton;