iam new in this field and I want to make bot using selenium to fill google form website using this code
from selenium import webdriver
import time
from datetime import datetime
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
today_date = datetime.today().strftime('%Y-%m-%d')
driver = webdriver.Chrome()
#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)
next = driver.find_element_by_css_selector("#mG61Hd > div.freebirdFormviewerViewFormCard.exportFormCard > div > div.freebirdFormviewerViewNavigationNavControls > div > div.freebirdFormviewerViewNavigationLeftButtons > div > span").click()
but i cant click next. Google form doesn't recognize the date
CodePudding user response:
You can use the below xpath to click on Next button.
//span[text()='Next']/..
In code :
today_date = datetime.today().strftime('%Y-%m-%d')
driver = webdriver.Chrome()
#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)
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Next']/.."))).click()
CodePudding user response:
I found a solution using actionchains, this is the code
from selenium import webdriver
import time
from datetime import datetime
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
today_date = datetime.today().strftime('%Y-%m-%d')
driver = webdriver.Chrome()
#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)
element =driver.find_element_by_xpath("//span[text()='Berikutnya']")
element.click()
time.sleep(1)
webdriver.ActionChains(driver).key_down(Keys.ARROW_RIGHT).send_keys("a").perform()
time.sleep(1)
element.click()