简体   繁体   中英

How to select a value from a google form drop down element using selenium python

I've been trying to automate completing a google form by selecting values from a google form drop-down menu but have not succeeded. I have used Select but got an error message saying Select only works on select elements. I'm relatively new to python and selenium library please help and thanks in advance.

Error: selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on elements, not on

Here is the google form I have been trying to automate https://docs.google.com/forms/d/e/1FAIpQLSf4Yo0lQIBOTi0ANskke1J7WhVbI_ruBYomp1xe231RZooPNw/viewform

Just open up the tag by clicking on it and then click the element you want.

driver.get("https://docs.google.com/forms/d/e/1FAIpQLSf4Yo0lQIBOTi0ANskke1J7WhVbI_ruBYomp1xe231RZooPNw/viewform")
wait = WebDriverWait(driver,10)
search = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.quantumWizMenuPaperselectOption.appsMaterialWizMenuPaperselectOption.freebirdThemedSelectOptionDarkerDisabled.exportOption.isSelected.isPlaceholder")))
search.click()     
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.exportSelectPopup.quantumWizMenuPaperselectPopup.appsMaterialWizMenuPaperselectPopup > div:nth-child(3) > span"))).click()

Import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

This is not good practice in selenium.

For multiple reasons, logging into sites like Gmail and Facebook using WebDriver is not recommended. Aside from being against the usage terms for these sites (where you risk having the account shut down), it is slow and unreliable.

The ideal practice is to use the APIs that email providers offer, or in the case of Facebook the developer tools service which exposes an API for creating test accounts, friends, and so forth. Although using an API might seem like a bit of extra hard work, you will be paid back in speed, reliability, and stability. The API is also unlikely to change, whereas webpages and HTML locators change often and require you to update your test framework.

Logging in to third-party sites using WebDriver at any point of your test increases the risk of your test failing because it makes your test longer. A general rule of thumb is that longer tests are more fragile and unreliable.

WebDriver implementations that are W3C conformant also annotate the navigator object with a WebDriver property so that Denial of Service attacks can be mitigated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM