在 google 表单上使用 sendkeys 时,Selenium ““元素不可交互异常”?

Selenium "“element not interactable exception" while using sendkeys on google Form?

我正在尝试使用 python3.9

中的硒来填写 google 表格

https://docs.google.com/forms/d/e/1FAIpQLSead7qqhVWP4m4q9Y71Wu9kr2lbCQXvY4ge0OdFg9fI0SQYYA/viewform

但我在 form[0] 处收到“元素不可交互异常”错误。send_keys('222')

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from constants import FORM_URL, CHROME_DRIVER_LOCATION


class FillForm:
    def __init__(self, form = FORM_URL):
        self.driver = webdriver.Chrome(executable_path=CHROME_DRIVER_LOCATION)
        self.driver.get(form)

    def fill_form(self, data: dict):
        form = self.driver.find_elements_by_class_name('exportInput')
        form[0].send_keys('222') #ERROR IS HERE

我阅读了线程 b 来解决问题,但似乎我做错了什么

我在 Whosebug 上读到的主题 How do you fix the "element not interactable" exception?

我做错了什么?

您可能在初始化 FillForm 对象后立即调用 fill_form。尝试为您的 fill_form 函数添加显式等待。

from time import sleep
from selenium import webdriver
import selenium.webdriver.support.expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

class FillForm:
    def __init__(self, form):
        self.driver = webdriver.Chrome()
        self.driver.get(form)

    def fill_form(self, data: list, class_name='exportInput'):
        WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, 'exportInput')))
        form = self.driver.find_elements_by_class_name(class_name)
        for i, value in enumerate(data):
            form[i].send_keys(value) 

只是需要等待。在Java

        WebElement inputElement1 = driver.findElement(By.cssSelector("input[jsname='YPqjbf']"));
        WebDriverWait wait = new WebDriverWait(driver, 5000);
        wait.until(ExpectedConditions.visibilityOf(inputElement1));
        inputElement1.sendKeys("222");