0

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 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

1 Comment

Truth be told...I was looking at it more than 5 times, and still it didn't catch my eye...;) THank you...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.