【发布时间】:2016-01-20 03:33:58
【问题描述】:
以这个 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)", "");
【问题讨论】: