1
私はAJAXとjqueryでWebを扱おうとしています。このように、成功事例のなしで、私は特定のセクションに達するまでスクロールダウンしたいので、私は待つとECとのいくつかのアプローチをした:WebDriverWaitとexpected_conditionsを使ったwhileステートメントの使用
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に対処する方法がするまで何かをするために、ありますいくつかの要素が表示され、クリック可能ですか?
EDIT:
私はJavaScriptを使用して、いくつかの汚い手口をしましたが、間違いなく私の目標に到達するためのニシキヘビの方法ではありません。
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