【发布时间】:2019-05-30 04:21:58
【问题描述】:
我正在尝试从
收集一些数据https://www.91mobiles.com/phonefinder.php
我必须等待 ajax 调用才能获得“下一步”按钮,但 WebDriverWait 似乎被忽略(不会被命中)而没有断点。 以前它可以工作 2 周,但现在不行了。
- 我以为是 web 驱动 -> 改成 chrome 而不是 firefox 但结果是一样的
- 将每个包更新到最新 -> 相同
- 尝试使用具有相同实现的 C# -> 有效,我不知道为什么 => 总结一下,也许问题不在他们的网站上
C# 语法:
Driver.ExecuteScript("window.scrollTo({ top: document.body.scrollHeight || document.documentElement.scrollHeight, behavior: 'smooth' });");
Wait.Until(s => s.FindElement(By.CssSelector('div#finder_pagination>div.listing-btns>div.listing-btns4>span')));
Driver.ExecuteScript("window.scrollTo({ top: 0, behavior: 'smooth' });");
// Work as expected
...
Python 语法:
# Scroll to bottom for AJAX loading
self.browser.execute_script('window.scrollTo({ top: document.body.scrollHeight || document.documentElement.scrollHeight, behavior: "smooth" });')
# timeout is 30 seconds, execution will be delayed until the 'NEXT' button found
self.wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'div#finder_pagination>div.listing-btns>div.listing-btns4>span')))
# after that, scroll back to top
self.browser.execute_script('window.scrollTo({ top: 0, behavior: "smooth" });')
# The web does not wait, it scroll right away and execute the next code
...
提前致谢
【问题讨论】:
标签: python-3.x selenium python-3.7 webdriverwait