0
votes

I am trying to create ajax wait method in Java with Selenium for fetching as many results as defined by configuration.

Here is my method:

    /**
     * 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;
    }

And here is my call:

List<WebElement> videoElements = waitAjaxLoad(By.xpath("//div[@id='pageTv']/div[@id='pageTvScroller')]/div[@class='boxInner']/ul/li"));

And I get this exception:

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

Should I wory about XPath expression not being snytax correct, or Selenium can't find that WebElement? This exception is ambiguous to me....

1

1 Answers

0
votes

Its a simple typing error, an unwanted round bracket is added in div[@id='pageTvScroller')],so replace

 //div[@id='pageTv']/div[@id='pageTvScroller')]/div[@class='boxInner']/ul/li

with

//div[@id='pageTv']/div[@id='pageTvScroller']/div[@class='boxInner']/ul/li