[英]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.
我使用了 Select 但收到一条错误消息,说 Select 仅适用于 select 元素。 I'm relatively new to python and selenium library please help and thanks in advance.
我对 python 和 selenium 库比较陌生,请提前帮助和感谢。
Error: selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on elements, not on错误:selenium.common.exceptions.UnexpectedTagNameException:消息:Select 仅适用于元素,不适用于
Here is the google form I have been trying to automate https://docs.google.com/forms/d/e/1FAIpQLSf4Yo0lQIBOTi0ANskke1J7WhVbI_ruBYomp1xe231RZooPNw/viewform这是我一直在尝试自动化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.这在 selenium 中不是很好的做法。
For multiple reasons, logging into sites like Gmail and Facebook using WebDriver is not recommended.出于多种原因,不建议使用 WebDriver 登录 Gmail 和 Facebook 等网站。 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.理想的做法是使用 email 提供商提供的 API,或者在 Facebook 的情况下,开发人员工具服务公开了 API 用于创建测试帐户、朋友等。 Although using an API might seem like a bit of extra hard work, you will be paid back in speed, reliability, and stability.
尽管使用 API 可能看起来有点额外的艰苦工作,但您将在速度、可靠性和稳定性方面得到回报。 The API is also unlikely to change, whereas webpages and HTML locators change often and require you to update your test framework.
API 也不太可能发生变化,而网页和 HTML 定位器经常变化,需要您更新测试框架。
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.在测试的任何时候使用 WebDriver 登录第三方站点都会增加测试失败的风险,因为它会延长测试时间。 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.符合 W3C 的 WebDriver 实现还使用 WebDriver 属性注释导航器 object,以便可以缓解拒绝服务攻击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.