Reputation: 63
Drop Down Menus in google forms don't use any tags and use tags and java. I haven't been able to find anything that can select from a dropdown menu in google forms. The HTML of their dropdown menus is way too long, so for the sake of space, I will provide an example google form.
Upvotes: 2
Views: 430
Reputation: 19
Dear try this, and i think this will be working
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()
Upvotes: 2
Reputation: 1556
This page has a custom select and options, not default one. You should work with it as with regular web elements, just use regular locators to find elements and then interact.
Try this:
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("//div[@role='option' and contains(@class, 'isPlaceholder')]").click()
sleep(1) # Wait for options to load
options = driver.find_elements_by_xpath("//div[@role='option' and not(contains(@class, 'isPlaceholder'))]")
# And now, let's click on the 4th one by index:
options[3].click()
Hope this helps, good lick!
Upvotes: 1
Reputation: 31
I typically handles this by waiting until the drop-down is found by Selenium, then a macro or RPA tool like Approbotic to click on it and navigate through the options (while adjusting the timing in between each click or option move). Something like this should work for you:
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)
Upvotes: 3