3 回答

TA貢獻1853條經驗 獲得超18個贊
我通常通過等待 Selenium 找到下拉菜單來處理此問題,然后使用宏或 RPA 工具(例如 Appprobotic)單擊它并瀏覽選項(同時調整每次單擊或選項移動之間的時間)。像這樣的東西應該適合你:
import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
from selenium import webdriver
# navigate to Google Form
driver = webdriver.Firefox()
driver.get('https://forms.gle/SZftJSkvy9YWbktF9')
# sleep 1 second
x.Wait(1000)
link = driver.find_element_by_link_text('Mail')
if len(link) > 0
link[0].click()
# sleep 1 second
x.Wait(1000)
# press down arrow key
x.PressDownArrow
x.Wait(100)
x.PressDownArrow
x.Wait(100)

TA貢獻1804條經驗 獲得超8個贊
親愛的試試這個,我想這會起作用的
from selenium import webdriver
import time
driver = webdriver.Chrome("chromedriver/chromedriver")
driver.get('https://docs.google.com/forms/d/e/1FAIpQLSdpyJ9UBFtsQDZHhK7KsYuILm5kh68jvY5DeFAKIBPTxx4RCQ/viewform')
'''For click drop down'''
driver.find_element_by_xpath('//*[@id="mG61Hd"]/div/div/div[2]/div/div/div[2]').click()
'''Time for wait --> 1 second'''
time.sleep(1)
'''Select the option '''
driver.find_element_by_xpath('//*[@id="mG61Hd"]/div/div/div[2]/div/div/div[2]/div[2]/div[4]/span').click()

TA貢獻1847條經驗 獲得超7個贊
此頁面有自定義選擇和選項,而不是默認選項。您應該像使用常規 Web 元素一樣使用它,只需使用常規定位器來查找元素然后進行交互即可。
嘗試這個:
driver = webdriver.Chrome()
driver.get("https://docs.google.com/forms/d/e/1FAIpQLSdpyJ9UBFtsQDZHhK7KsYuILm5kh68jvY5DeFAKIBPTxx4RCQ/viewform")
driver.implicitly_wait(4)
# Click on top option placeholder to open a drop down:
driver.find_element_by_xpath("http://div[@role='option' and contains(@class, 'isPlaceholder')]").click()
sleep(1) # Wait for options to load
options = driver.find_elements_by_xpath("http://div[@role='option' and not(contains(@class, 'isPlaceholder'))]")
# And now, let's click on the 4th one by index:
options[3].click()
希望這有幫助!
- 3 回答
- 0 關注
- 147 瀏覽
添加回答
舉報