以这个 Instagram 链接为例。 https://www.instagram.com/janelaverdegarden/ ,我想通过滚动到页面底部来加载所有图像。为此,我必须单击“加载更多”按钮,向下滚动到底部页面,等待页面加载,向上滚动一点,然后向下滚动到底部页面并等待页面再次加载,直到不再留下任何图像(手动) .
但是,我想使用 Selenium 自动加载页面。因此,最初,我认为一旦页面完全加载到页面末尾并包含所有图像,Web 元素 rbSensor
将消失,允许我标记页面已到达底部无需加载更多图像。然而,它仍然留在那里。那么有没有其他方法来检查页面是否已完全加载所有图像?
<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>
代码。当我使用 rbSensor 加载页面时,即使页面完全加载了所有图像,该元素仍然会被连续单击,因为该元素仍在 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
}
使用 Page scroll up or down in Selenium WebDriver (Selenium 2) using java 中的以下答案不是我想要的,在这种情况下不起作用。
jse.executeScript("window.scrollBy(0,250)", "");
最佳答案
尝试使用不同的类名
className("_oidfu")
有 href 属性
可以在这里找到滚动答案:Page scroll up or down in Selenium WebDriver (Selenium 2) using java
关于java - 向下滚动到页面底部加载 Instagram 图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34891100/