zoukankan      html  css  js  c++  java
  • selenium处理页面select元素

    selenium为网页中选择框元素的获取特别引入了一个Select对象,

    引入对象的方式:

     from selenium.webdriver.support.ui import Select 

    查询文档可以知道 Select 所支持的方法:

    class selenium.webdriver.support.select.Select(webelement)[source]
    Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not, then an UnexpectedTagNameException is thrown.
    
    Args :    
    webelement - element SELECT element to wrap
    Example:
    from selenium.webdriver.support.ui import Select # 引入
    
    Select(driver.find_element_by_tag_name(“select”)).select_by_index(2) # 获取select元素
    
    all_selected_options[source]
    Returns a list of all selected options belonging to this select tag
    
    deselect_all()[source]
    Clear all selected entries. This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections
    
    deselect_by_index(index)[source]
    Deselect the option at the given index. This is done by examing the “index” attribute of an element, and not merely by counting.
    
    Args :    
    index - The option at this index will be deselected
    throws NoSuchElementException If there is no option with specisied index in SELECT
    
    deselect_by_value(value)[source]
    Deselect all options that have a value matching the argument. That is, when given “foo” this would deselect an option like:
    
    <option value=”foo”>Bar</option>
    Args :    
    value - The value to match against
    throws NoSuchElementException If there is no option with specisied value in SELECT
    
    deselect_by_visible_text(text)[source]
    Deselect all options that display text matching the argument. That is, when given “Bar” this would deselect an option like:
    
    <option value=”foo”>Bar</option>
    
    Args :    
    text - The visible text to match against
    first_selected_option[source]
    The first selected option in this select tag (or the currently selected option in a normal select)
    
    options[source]
    Returns a list of all options belonging to this select tag
    
    select_by_index(index)[source]
    Select the option at the given index. This is done by examing the “index” attribute of an element, and not merely by counting.
    
    Args :    
    index - The option at this index will be selected
    throws NoSuchElementException If there is no option with specisied index in SELECT
    
    select_by_value(value)[source]
    Select all options that have a value matching the argument. That is, when given “foo” this would select an option like:
    
    <option value=”foo”>Bar</option>
    
    Args :    
    value - The value to match against
    throws NoSuchElementException If there is no option with specisied value in SELECT
    
    select_by_visible_text(text)[source]
    Select all options that display text matching the argument. That is, when given “Bar” this would select an option like:
    
    <option value=”foo”>Bar</option>
    Args :    
    text - The visible text to match against
    throws NoSuchElementException If there is no option with specisied text in SELECT
  • 相关阅读:
    洛谷【P1480】A/B Problem
    bzoj 2654 && bzoj 3675 总结
    关于三维莫队问题的一些思考和探究
    BZOJ 1179 抢掠计划atm (缩点+有向无环图DP)
    BZOJ 1500 Luogu P2042 [NOI2005] 维护数列 (Splay)
    Codeforces 919D Substring (拓扑图DP)
    【学习笔记】有向无环图上的DP
    【学习笔记】求解简单递归式的一般方法
    BZOJ 3930 Luogu P3172 选数 (莫比乌斯反演)
    POJ 1061 BZOJ 1477 Luogu P1516 青蛙的约会 (扩展欧几里得算法)
  • 原文地址:https://www.cnblogs.com/yqmcu/p/10131328.html
Copyright © 2011-2022 走看看