1

I have followed the steps of another stackoverflow but cannot figure out how to achieve the goal.

Google Form

My code:

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()

The code works until it is supposed to select Option 2 form the dropdown. When it gets to this point it selects the dropdown button but doesn't select an option (picture below) enter image description here

Peter
  • 110
  • 8

1 Answers1

3

You can put this piece of code to where the program's supposed to select an option:

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'])
Red
  • 26,798
  • 7
  • 36
  • 58
  • Thanks it worked! I just added `time.sleep(3)` in between the for loop and when it writes enter – Peter Jun 10 '20 at 00:49
  • Is it possible to make this work in headless mode? @Ann Zen – Peter Jun 14 '20 at 17:35
  • This:https://stackoverflow.com/questions/46920243/how-to-configure-chromedriver-to-initiate-chrome-browser-in-headless-mode-throug/49582462. It doesn't open in a window. – Peter Jun 14 '20 at 18:28