简体   繁体   English

单击使用硒的下拉列表中的所有值

[英]Click all values in a drop down list using selenium

I'm scrapping a website 我正在抓取一个网站

http://tabnet.saude.prefeitura.sp.gov.br/cgi/deftohtm3.exe?secretarias/saude/TABNET/AIHRD08/AIHRDNET08.def http://tabnet.saude.prefeitura.sp.gov.br/cgi/deftohtm3.exe?secretarias/saude/TABNET/AIHRD08/AIHRDNET08.def

I need to select all values in the field Períodos Disponíveis . 我需要在Períodos Disponíveis字段中选择所有值。 I created a for loop to do it because the Xpath of field follow a sequence: 我创建了一个for循环来执行此操作,因为field的Xpath遵循一个序列:

element = browser.find_element_by_xpath('//*[@id="A"]')
all_options = element.find_elements_by_tag_name("option")
    for option in all_options:
        option.click()
browser.find_element_by_xpath('//*[@id="A"]/option[1]').click()

But this is too slow, how can I make this faster? 但这太慢了,我怎样才能更快呢?

I just tested and I have implemented keyboard shortcut. 我刚刚测试过,并且已经实现了键盘快捷键。 After identifying the element: 确定元素后:

element = browser.find_element_by_xpath('//*[@id="A"]')

Use send keys 使用发送键

element.send_keys(Keys.SHIFT + Keys.END)

Assumption is that you have already declared Keys as: 假设您已经将Keys声明为:

from selenium.webdriver.common.keys import Keys

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 蟒蛇硒| 如何使用索引获取所有下拉列表值,复杂下拉结构 - Python selenium | How to fetch all the drop down list values using index , Complex drop down structure 使用 selenium 从下拉列表中获取所有值和项目 - Get all value and items from drop down list using selenium 如何使用长下拉列表中的selenium单击元素? - How do i click an element using selenium from a long drop down list? Selenium WebDriver可以从下拉菜单中单击所有组合 - Can Selenium WebDriver click on all combinations from drop down menu 如何单击使用 Selenium 隐藏的下拉菜单? - How do I click on a drop down menu that is hidden using Selenium? 使用 selenium Python 库单击下拉菜单中的项目 - Click an item in a drop-down menu using selenium Python library 无法使用硒Python在Ajax网页中单击下拉选项 - Not able to click on drop down option in a ajax webpage using selenium python 如何使用Selenium和Chrome单击Python中的下拉菜单 - How to click on drop down menu in Python using Selenium and Chrome 单击并使用python 2 selenium选择javascript下拉菜单的值 - click and select value of javascript drop down menu using python 2 selenium 如何使用 selenium webdriver python 单击呼叫下拉列表? - How to click the call drop down using selenium webdriver python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM