如何使用 selenium 滚动本地 div 元素

how to scroll a local div element with selenium

我正在尝试使用 driver.find_element_by_xpath(element).send_keys(Keys.PAGE_DOWN)

滚动浏览本地 div 元素

问题是 element 不是接受键输入的元素,所以代码抛出一个 selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

我宁愿使用pyautogui来模拟鼠标和键盘功能

pyautogui.moveTo(663,680)
pyautogui.click(663,680)

pyautogui.scroll(-200)
time.sleep(2)

但我想将代码保留在浏览器中

有什么解决办法吗?

driver.execute_script("arguments[0].scrollIntoView(true)", element)