在Selenium中,有没有一种方法可以从GoogleForms(python)中的下拉菜单中选择一个选项
谷歌表单中的下拉菜单不使用任何标签,而是使用标签和java。我在谷歌表单中找不到任何可以从下拉菜单中选择的内容。他们下拉菜单的HTML太长了,所以为了节省空间,我将提供一个google表单示例在Selenium中,有没有一种方法可以从GoogleForms(python)中的下拉菜单中选择一个选项,python,html,selenium,drop-down-menu,google-forms,Python,Html,Selenium,Drop Down Menu,Google Forms,谷歌表单中的下拉菜单不使用任何标签,而是使用标签和java。我在谷歌表单中找不到任何可以从下拉菜单中选择的内容。他们下拉菜单的HTML太长了,所以为了节省空间,我将提供一个google表单示例 我通常会等待Selenium找到下拉列表,然后使用宏或RPA工具(如Approbotic)单击该下拉列表并浏览选项(同时调整每次单击或选项移动之间的时间)。像这样的东西应该适合你: import win32com.client x = win32com.client.Dispatch("AppRoboti
我通常会等待Selenium找到下拉列表,然后使用宏或RPA工具(如Approbotic)单击该下拉列表并浏览选项(同时调整每次单击或选项移动之间的时间)。像这样的东西应该适合你:
import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
from selenium import webdriver
# navigate to Google Form
driver = webdriver.Firefox()
driver.get('https://forms.gle/SZftJSkvy9YWbktF9')
# sleep 1 second
x.Wait(1000)
link = driver.find_element_by_link_text('Mail')
if len(link) > 0
link[0].click()
# sleep 1 second
x.Wait(1000)
# press down arrow key
x.PressDownArrow
x.Wait(100)
x.PressDownArrow
x.Wait(100)
我通常会等待Selenium找到下拉列表,然后使用宏或RPA工具(如Approbotic)单击该下拉列表并浏览选项(同时调整每次单击或选项移动之间的时间)。像这样的东西应该适合你:
import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
from selenium import webdriver
# navigate to Google Form
driver = webdriver.Firefox()
driver.get('https://forms.gle/SZftJSkvy9YWbktF9')
# sleep 1 second
x.Wait(1000)
link = driver.find_element_by_link_text('Mail')
if len(link) > 0
link[0].click()
# sleep 1 second
x.Wait(1000)
# press down arrow key
x.PressDownArrow
x.Wait(100)
x.PressDownArrow
x.Wait(100)
此页面具有自定义的选择和选项,而不是默认选项。您应该像处理常规web元素一样使用它,只需使用常规定位器查找元素,然后进行交互 试试这个:
driver = webdriver.Chrome()
driver.get("https://docs.google.com/forms/d/e/1FAIpQLSdpyJ9UBFtsQDZHhK7KsYuILm5kh68jvY5DeFAKIBPTxx4RCQ/viewform")
driver.implicitly_wait(4)
# Click on top option placeholder to open a drop down:
driver.find_element_by_xpath("//div[@role='option' and contains(@class, 'isPlaceholder')]").click()
sleep(1) # Wait for options to load
options = driver.find_elements_by_xpath("//div[@role='option' and not(contains(@class, 'isPlaceholder'))]")
# And now, let's click on the 4th one by index:
options[3].click()
希望这有帮助,好舔 此页面具有自定义的选择和选项,而不是默认选项。您应该像处理常规web元素一样使用它,只需使用常规定位器查找元素,然后进行交互 试试这个:
driver = webdriver.Chrome()
driver.get("https://docs.google.com/forms/d/e/1FAIpQLSdpyJ9UBFtsQDZHhK7KsYuILm5kh68jvY5DeFAKIBPTxx4RCQ/viewform")
driver.implicitly_wait(4)
# Click on top option placeholder to open a drop down:
driver.find_element_by_xpath("//div[@role='option' and contains(@class, 'isPlaceholder')]").click()
sleep(1) # Wait for options to load
options = driver.find_elements_by_xpath("//div[@role='option' and not(contains(@class, 'isPlaceholder'))]")
# And now, let's click on the 4th one by index:
options[3].click()
希望这有帮助,好舔 亲爱的试试这个,我想它会起作用的
from selenium import webdriver
import time
driver = webdriver.Chrome("chromedriver/chromedriver")
driver.get('https://docs.google.com/forms/d/e/1FAIpQLSdpyJ9UBFtsQDZHhK7KsYuILm5kh68jvY5DeFAKIBPTxx4RCQ/viewform')
'''For click drop down'''
driver.find_element_by_xpath('//*[@id="mG61Hd"]/div/div/div[2]/div/div/div[2]').click()
'''Time for wait --> 1 second'''
time.sleep(1)
'''Select the option '''
driver.find_element_by_xpath('//*[@id="mG61Hd"]/div/div/div[2]/div/div/div[2]/div[2]/div[4]/span').click()
亲爱的试试这个,我想它会起作用的
from selenium import webdriver
import time
driver = webdriver.Chrome("chromedriver/chromedriver")
driver.get('https://docs.google.com/forms/d/e/1FAIpQLSdpyJ9UBFtsQDZHhK7KsYuILm5kh68jvY5DeFAKIBPTxx4RCQ/viewform')
'''For click drop down'''
driver.find_element_by_xpath('//*[@id="mG61Hd"]/div/div/div[2]/div/div/div[2]').click()
'''Time for wait --> 1 second'''
time.sleep(1)
'''Select the option '''
driver.find_element_by_xpath('//*[@id="mG61Hd"]/div/div/div[2]/div/div/div[2]/div[2]/div[4]/span').click()
这些元素不是下拉列表,而是一组“Div”元素。您需要定义自定义函数来实现这一点。xPath可以方便地实现这一点。元素不是下拉式的,而是一组“Div”元素。您需要定义自定义函数来实现这一点。xPath可以方便地实现这一点。