尝试从下拉列表中选择第二个值。下拉菜单由div类组成。
来自常量类:
public static final String HOME_PAGE_FLYING_FROM_ID = "departureAirport";
public static final String FLYING_FROM_AJAX_XPATH = "//div[contains(@class,'autocompletebox') and (rel,'departureAirport')]/p[2]/a";
来 self 的 FlightSearch 类(class):
@FindBy(how = How.ID, using = HOME_PAGE_FLYING_FROM_ID)
WebElement flyingFrom;
@FindBy(how = How.XPATH, using = FLYING_FROM_AJAX_XPATH)
WebElement flyingFromAjaxValue;
public void simpleFlighSearch() {
flyingFrom.sendKeys("new");
action.moveToElement(flyingFromAjaxValue).click().build().perform();
LOGGER.debug("clicked`");
}
这是我收到的错误: 无效选择器:无法使用 xpath 表达式定位元素。无法对“文档”执行“评估”。
最佳答案
很可能您在 XPath 中错过了另一个“包含”和“@”,它应该如下所示:
//div[contains(@class,'autocompletebox') and contains(@rel,'departureAirport')]/p[2]/a
关于java - 无效选择器 : Unable to locate an element with the xpath expression. 无法在 'evaluate' 上执行 'Document',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28900209/