Taking this instagram link for eg. https://www.instagram.com/janelaverdegarden/, I want to load all the images by scrolling to the bottom of the page. To do that, I have to click LOAD MORE button, scroll down to bottom page, wait for page to load, scroll up abit, and scroll down to bottom page and wait for page to load again till no more images are left (manually).
However, I want to load the page automatically using Selenium. Thus, initially, I thought that once the page is fully loaded to the end of the page with all the images, the web element rbSensor
will disappear, allowing me to mark that the page has reached the bottom with no more images to be loaded. However, it still remains there. So is there any other way to check if the page is fully loaded with all the images?
<div data-reactid=".0.1.0.1:$mostRecentSection/=10">
<div class="_nljxa" data-reactid=".0.1.0.1:$mostRecentSection/=10.0">
<div class="ResponsiveBlock" data-reactid=".0.1.0.1:$mostRecentSection/=10.1">
<div class="rbSensor" data-reactid=".0.1.0.1:$mostRecentSection/=10.1.$sensor">
<iframe class="rbSensorFrame" data-reactid=".0.1.0.1:$mostRecentSection/=10.1.$sensor.0"/>
</div>
</div>
</div>
Code. As I used rbSensor
to load the page, even if the page is fully loaded with all the images, the element will still be clicked continuously as the element is still in the html.
while (driver.findElements(By.className("rbSensor")).size() > 0) {
jse.executeScript("window.scrollTo(0,-300)"); //scroll up abit
//click on button if found
driver.findElement(By.className("rbSensor")).click();
Thread.sleep(2000); //pause for 2 seconds
}
Using the answer below in Page scroll up or down in Selenium WebDriver (Selenium 2) using java is not what I want and will not work in this case.
jse.executeScript("window.scrollBy(0,250)", "");