Wait for the page to load links
Change your code to
dr.get("https://www.ebay.com");
waitForLoad(dr);
List<WebElement> linksize = dr.findElements(By.tagName("a"));
System.out.println(linksize.size());
You can use the method below as your resource and you can call anytime.
void waitForLoad(WebDriver driver) {
ExpectedCondition<Boolean> pageLoadCondition = new
ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(pageLoadCondition);
}
source
share