I want to automate filling google forms with the images in google drive so I am using python with selenium.
The first image I can automate, but I got the error when I repeated the same process for the second image.
I created a sample google form to test.
Full code:
from selenium import webdriver
import random,time
option=webdriver.ChromeOptions()
driver = webdriver.Chrome("path to chrome driver")
driver.get("https://forms.gle/RvBYTZG5xuWoD8QA7")
driver.find_element_by_xpath('//*[@id="identifierId"]').send_keys("gmail")
driver.find_element_by_xpath('//*[@id="identifierNext"]/div/button').click()
time.sleep(3)
driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys("password")
driver.find_element_by_xpath('//*[@id="passwordNext"]/div/button').click()
time.sleep(5)
driver.find_element_by_xpath('//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[2]/span').click()
frame1 = driver.find_element_by_class_name('picker-frame')
driver.switch_to.frame(frame1)
driver.find_element_by_xpath('//*[@id=":6"]').click()
time.sleep(5)
driver.find_element_by_xpath('//*[@id=":1a.docs.0.1oe7tESa9uNnUC75FdYuqzPtPbLYz7QFi"]/div[2]').click()
driver.find_element_by_xpath('//*[@id="picker:ap:2"]').click()
driver.switch_to_default_content()
driver.find_element_by_xpath('//*[@id="mG61Hd"]/div[2]/div/div[2]/div[2]/div/div/div[2]/div/div[2]').click()
frame2 = driver.find_element_by_class_name('picker-frame')
driver.switch_to.frame(frame2)
driver.find_element_by_xpath('//*[@id=":6"]').click()
time.sleep(3)
CodePudding user response:
This is a guess since no HTML was provided but maybe the location in the iframe of the element isnt correct since if you give it the global iframe path it want work i suggest to check if the button has a specifique i frame and switch to that iframe and give it the path in that one. Or the element path isn't unique that makes problems too.
CodePudding user response:
I think you are typing it wrongly. You should try this code.
driver.switch_to.default_content()