使用python selenium从google表单下拉列表中选择选项

使用python selenium从google表单下拉列表中选择选项,python,forms,selenium,Python,Forms,Selenium,我遵循了的步骤,但不知道如何实现目标 我的代码: from selenium.webdriver.support.select import Select from selenium.webdriver.chrome.webdriver import WebDriver url = "https://docs.google.com/forms/d/e/1FAIpQLSds6e0UN4V9j3eNvZ3Tm6kRVEC0Ak74m4rBB8IGJIUEnTGmaw/formResponse

我遵循了的步骤,但不知道如何实现目标

我的代码:

from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.webdriver import WebDriver



url = "https://docs.google.com/forms/d/e/1FAIpQLSds6e0UN4V9j3eNvZ3Tm6kRVEC0Ak74m4rBB8IGJIUEnTGmaw/formResponse"

def foo(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()
该代码一直工作,直到应该从下拉列表中选择选项2为止。当它到达这一点时,它选择下拉按钮,但不选择选项(下图)

您可以将这段代码放在程序应该选择选项的位置:

from pyautogui import write

option_number = 3 # Choose option number here

# Put this where the program's supposed to select an option
for _ in range(option_number):
    write(['down'])
write(['enter'])

谢谢,成功了!我刚刚在for循环和写入enter之间添加了
time.sleep(3)
,可以在headless模式下工作吗@安Zen@peeeeeta无头模式?此:。它不能在窗口打开。