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’)
JavaScript
x
15
15
1
from time import sleep
2
from selenium import webdriver
3
from selenium.webdriver.common.keys import Keys
4
from constants import FORM_URL, CHROME_DRIVER_LOCATION
5
6
7
class FillForm:
8
def __init__(self, form = FORM_URL):
9
self.driver = webdriver.Chrome(executable_path=CHROME_DRIVER_LOCATION)
10
self.driver.get(form)
11
12
def fill_form(self, data: dict):
13
form = self.driver.find_elements_by_class_name('exportInput')
14
form[0].send_keys('222') #ERROR IS HERE
15
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.
JavaScript
1
17
17
1
from time import sleep
2
from selenium import webdriver
3
import selenium.webdriver.support.expected_conditions as EC
4
from selenium.webdriver.support.ui import WebDriverWait
5
from selenium.webdriver.common.by import By
6
7
class FillForm:
8
def __init__(self, form):
9
self.driver = webdriver.Chrome()
10
self.driver.get(form)
11
12
def fill_form(self, data: list, class_name='exportInput'):
13
WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, 'exportInput')))
14
form = self.driver.find_elements_by_class_name(class_name)
15
for i, value in enumerate(data):
16
form[i].send_keys(value)
17