2

I have this part of code:

try {
Document doc=Jsoup.parse(broswer.getPageSource(),broswer.getCurrentUrl());
                return doc;
} catch (Exception ex) {
    event.log("Error while creating JSOUP document", ex);
}

the problem is that it randomly hangs on getPageSource(). Sometimes test can run for few hours without problem and sometimes it hangs on getPageSource(). I have tried latest selenium/ latest chrome, but also few previous combination and its still giving me same problem. This problem did not occurs with Firefox driver.

Is there any workaround? Like limiting time for getPageSource()?

  • 1
    Does it hang forever or there some exception arises eventually? – Alexey R. Apr 18 '18 at 14:10
  • Have you tried putting browser.getPageSource() and the Parsing into two two different lines? It might be possible that JSOUP runs into some infinite recursion while trying to parse it since getPageSource() is an incredibly straight forward method (other than the legendarily complicated task of parsing HTML). If it really happens within getPageSource I'd like to see the stack trace since that could really only be a problem with the JSON wire protocol which would be bad. – Daniel Apr 21 '18 at 20:55
1

You may choose an element which exists in your page and wait for it

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.refreshed(ExpectedConditions.visibilityOfElementLocated(by.Id("anElementIDInThePage"))));

and then

mysource = browser.getPageSource()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.