我想用谷歌驅動器中的影像自動填充谷歌表單,所以我使用 python 和 selenium。
我可以自動處理第一張影像,但是當我對第二張影像重復相同的程序時出現錯誤。
我創建了一個示例谷歌表單來測驗。


完整代碼:
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)
uj5u.com熱心網友回復:
這是一個猜測,因為沒有提供 HTML 但也許元素在 iframe 中的位置不正確,因為如果你給它全域 iframe 路徑它想要作業我建議檢查按鈕是否有特定的 i 框架并切換到該 iframe并給它那個路徑。或者元素路徑不是唯一的,也會產生問題。
uj5u.com熱心網友回復:
我認為你打錯了。你應該試試這個代碼。
driver.switch_to.default_content()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/366542.html
上一篇:如何從字串中減去并保留前導零
下一篇:無法在其他頁面中獲取“href”
