I'm scraping a website, which for some reason takes 15 seconds to load, but the elements I need get loaded in the first 5 seconds.
The question is, can I stop loading a page, and move on with the code when the code is already present?
driver.Navigate().GoToUrl(url);
new WebDriverWait(driver, TimeSpan.FromSeconds(20))
.Until(ExpectedConditions.ElementIsVisible(By.XPath(xpath)));
driver.Navigate().GoToUrl(url);
WebDriverWait
functionAll of the solutions in similar questions are called after the page fully loaded, making the answer useless.
Can I do something about it? Thank you.
Method .Navigate().GoToUrl is created such a way that next line is executed only when page gets fully loaded. so yes, it doesn't matter what you are writing in code, after navigate method, it will never work until the page gets fully loaded. As a workaround you can opt for timeout option, with this it will throw a exception as page remains to load so we should catch that and execute our next code.
//This is java code, so please pick only the logic from here:
// Set the page load timeout to 10 seconds.
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
try {
driver.Navigate().GoToUrl(url);
} catch (TimeoutException e) {
// Ignore the exception.
}