Home > Net >  Pick date in google form with selenium
Pick date in google form with selenium

Time:09-26

so I try to make a bot using selenium in python and I stuck in date form here the code

from selenium import webdriver
from selenium.webdriver import ActionChains
import time

driver = webdriver.Chrome()
driver.maximize_window() # For maximizing window
driver.implicitly_wait(20) # gives an implicit wait for 20 seconds
website = driver.get("https://forms.gle/VUwbshGuXxDb7NRbA")
time.sleep(1)
tanggal = driver.find_element_by_xpath("//*[@id="mG61Hd"]/div[2]/div/div[2]/div/div/div/div[2]/div/div/div[2]/div[1]/div/div[1]/input").send_keys("12")

I already tried using click() and send_keys() but it won't work

CodePudding user response:

  1. Use explicit waits.
  2. I could update the date with the help of JS setAttribute.
  3. Date format is yyyy-mm-dd

Code :

from datetime import datetime
today_date = datetime.today().strftime('%Y-%m-%d')

driver = webdriver.Chrome(driver_path)
driver.maximize_window()
#driver.implicitly_wait(30)
wait = WebDriverWait(driver, 30)
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.implicitly_wait(30)
wait = WebDriverWait(driver, 30)
driver.get("https://forms.gle/VUwbshGuXxDb7NRbA")
time.sleep(1)
date= wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.quantumWizTextinputPaperinputInput")))
driver.execute_script(f"arguments[0].setAttribute('value', '{today_date}')", date)

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
  • Related