Python Selenium 如何 select google 表单中的下拉选项

Python Selenium how to select a dropdown option in a google form

我无法select此下拉菜单的不同选项 在字段 SIZE

https://docs.google.com/forms/d/e/1FAIpQLSdSpGLXjAV_wiI2qgg3B_KYxd4_7NR-DxHGrTySaIkAWIqmBg/viewform

谁有好的解决办法? 我可以用

点击元素
driver.find_element_by_xpath('/html/body/div/div[2]/form/div[2]/div/div[2]/div[14]/div/div/div[2]/div/div[1]/div[1]/div[1]').click()     

但我无法select不同的选项

突出显示 SIZE 和 right-click 并单击检查。现在再做一次,它会把你带到 HTML 关于那个。继续从那个 HTML 的根部向下,直到找到您想要的尺寸部分(当您将鼠标悬停在代码上时,它会突出显示网站中的相关部分)。希望这对您的代码功能有足够的帮助。

您需要单击列表将其打开,然后找到并单击其中包含正确内容的范围。由于有一点绘图延迟,您可能希望它使用 webdriverwait 来确保元素在交互之前准备就绪。

这对我有用:

driver = webdriver.Chrome()

driver.get("https://docs.google.com/forms/d/e/1FAIpQLSdSpGLXjAV_wiI2qgg3B_KYxd4_7NR-DxHGrTySaIkAWIqmBg/viewform")


#open the size menu
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[text()='SIZE']/following::div[@class='quantumWizMenuPaperselectOptionList'][1]"))).click()

#select the size by it's full text
sizeToSelect = "US 11"
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class,'exportSelectPopup')]/div/span[text()='"+sizeToSelect+"']"))).click()

如果您还没有得到它们,您需要导入以下内容:

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