在 Python 中使用 pyAutoGUI 滚动查看填充 Web 表单错误

问题描述

我有这个代码来填写网络表单:

driver.find_element_by_id("author").click()  # This opens the windows file selector
pyautogui.write('John')
pyautogui.press('enter')

但是如果给我一个错误

selenium.common.exceptions.ElementnotinteractableException: Message: Element <select id="author" class="select2-authors-multiple select2-hidden-accessible" name="author[]"> Could not be scrolled into view

我该如何解决这个问题?我尝试了一些代码,但它不起作用:

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

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);",element);
Thread.sleep(500); 

解决方法

因为您使用的是 pyautogui 尝试而不是滚动,所以使用箭头 down 进行导航,像这样 pyautogui.press("down")