I am trying to fill out the google form using selenium in python3.9
https://docs.google.com/forms/d/e/1FAIpQLSead7qqhVWP4m4q9Y71Wu9kr2lbCQXvY4ge0OdFg9fI0SQYYA/viewform
But I am getting an error at “element not interactable exception” at 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
I read the thread b to solve the issue but seems like I am doing something wrong
Thread I read at the stackoverflow How do you fix the “element not interactable” exception?
What I am doing wrong?
Advertisement
Answer
You are probably calling fill_form
right after initializing your FillForm
object. Try adding an explicit wait to your fill_form
function.
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)