1
我试图处理与AJAX和jQuery的网站。我要向下滚动,直到达到一定的部分,所以我也有等待和欧盟的一些方法,没有sucess,像这样:使用while语句与WebDriverWait和expected_conditions
scroll_bottom = """$('html, body').animate({scrollTop:$(document).height()},'fast');"""
from selenium.webdriver.common.by import By
# from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# wait = WebDriverWait(driver,10)
while EC.element_to_be_clickable((By.ID,"STOP_HERE")):
driver.execute_script(scroll_bottom)
有什么办法对付等待和EC,为了做一些事情,直到某些元素是可见的和/或可点击的?
编辑:
我做了一些肮脏的把戏与JavaScript,但绝对不是我达到目标的Python的方式。
def scroll_b():
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
driver.execute_script(load_jquery)
wait = WebDriverWait(driver,10)
js = """return document.getElementById("STOP_HERE")"""
selector = driver.execute_script(js)
while not selector :
driver.execute_script(scroll_bottom)
time.sleep(1)
selector = driver.execute_script(js)
print("END OF SCROLL")
这是一个聪明的解决方案,比我的方式更好。可惜的是webdriver是多么的可惜,以及它如何缺乏一种对语句友好的功能,以及“只是期望一种条件”。 谢谢! – peluzza