我想用Selenium在Java中创建ajax等待方法来获取配置定义的许多结果。Selenium xpath语法不正确
这里是我的方法:
/**
* Wait for WAIT seconds for AJAX data to be loaded.
* @throws Exception - if thread is interrupted
*/
public List<WebElement> waitAjaxLoad(By by) throws Exception{
int ajaxResultsWait = Integer.parseInt(P.getProperty("ajax.results.wait"));
List<WebElement> resultsLoaded = null;
do{
resultsLoaded = driver.findElements(by);
}while(resultsLoaded.size() < ajaxResultsWait);
return resultsLoaded;
}
这里是我的电话:
List<WebElement> videoElements = waitAjaxLoad(By.xpath("//div[@id='pageTv']/div[@id='pageTvScroller')]/div[@class='boxInner']/ul/li"));
我得到这个异常:
org.openqa.selenium.InvalidSelectorException: The given selector //div[@id='pageTv']/div[@id='pageTvScroller')]/div[@class='boxInner']/ul/li is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Unable to locate an element with the xpath expression //div[@id='pageTv']/div[@id='pageTvScroller')]/div[@class='boxInner']/ul/li because of the following error: [Exception... "The expression is not a legal expression." code: "12" nsresult: "0x805b0033 (SyntaxError)" location: ""] Command duration or timeout: 20 milliseconds
我应该wory约XPath表达式不是snytax正确,否则Selenium无法找到该WebElement?此异常暧昧我....
说实话......我看了5遍以上,仍然没有吸引我的目光......)谢谢你...... – Zec
很高兴帮助:) – Amith