如何使用python向下滚动网页上的小窗口?

2024-06-17 11:08:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做这件事

 html = browser.find_element_by_xpath('/html/body/div[4]/div/div/div[2]')
 html.send_keys(Keys.END)

ERROR=selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable


2条回答

你可以用 驱动程序.execute_脚本(“window.scrollTo(0,Y)”) 其中Y是高度(在全高清显示器上为1080)

您可以尝试将元素滚动到selenium视图中:

element = browser.find_element_by_xpath('/html/body/div[4]/div/div/div[2]')
driver.execute_script("arguments[0].scrollIntoView();", element)

或者,如果要垂直向下滚动:

driver.execute_script("window.scrollTo(0, Y)") 

Y可以是100, 200, and so on...

或者使用ActionChains

ActionChains(driver).move_to_element(html).perform()

相关问题 更多 >