此页面具有动态加载功能,在不同时间加载不同元素:
https://www.globo.com/
我使用了一个元素,我注意到它比其他元素花费的时间要长一些:
WebDriverWait(driver, 30).until(
EC.element_to_be_clickable(
(By.XPATH, "//div[contains(@class,'tooltip-vitrine')]")
但我想知道是否有任何方法可以跟踪元素加载到页面上的顺序,以找到一种模式,并使用一个总是比其他元素花费更长时间的元素,从而对页面的完整加载有更大的信心。
2条答案
按热度按时间yr9zkbsy1#
尝试this解决方案,您必须检查
document.readyState
并等待complete
返回。ktca8awb2#
我不知道是否有一种方法可以检查页面是否完全加载,因此我不知道是否有一种可靠的方法可以找到最后加载的元素。
一个简单的方法是在页面加载时检查页面中的元素数量:该数字应该增加,并且当页面完全加载时停止。
(注意,添加关于
document.readyState
的部分是为了检查Roman J的答案是否有效,但它似乎不起作用,因为即使接下来加载新元素,它也会打印complete
)产出
然后运行下面的命令来查看哪些是最后加载的元素(即它们的html代码
产出