instead of using sendKeys
you should use Select()
for drop down as below:
Ex.
If you have gender as drop down and you need to select gender you can select as below:
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.webdriver import WebDriver
driver = WebDriver() # setup web driver
driver.get(<url>) # retrive url
gender_select = Select(driver.find_element_by_name('gender')) # get element by name or id or xpath
gender_select.select_by_visible_text('Male') # here 'Male' is the text displayed on page so you can select item from dropdown menu by text visible in drop down menu
Update:
Select
won't work if tag is not select for your purpose here's the live demo:
def foo(url="https://docs.google.com/forms/d/e/1FAIpQLScbs4_3hPNYgjUO-hIa-H1OfJiDZ-FIY1WSk31jGyW5UtQ-Ow/viewform", opt="Option 2", delay=20):
from selenium.webdriver.chrome.webdriver import WebDriver
import time
driver = WebDriver()
driver.get(url)
driver.find_element_by_class_name("quantumWizMenuPaperselectOptionList").click()
options=driver.find_element_by_class_name("exportSelectPopup")
time.sleep(3)
print(options)
contents = options.find_elements_by_tag_name('content')
[i.click() for i in contents if i.text == opt]
foo()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…