zoukankan      html  css  js  c++  java
  • Python-selenium 下拉框定位

    1.通过select 进行定位下拉框

    首先selenium 很人性化的给提供了一个Select的模块,供处理下来菜单,首先我们需要导入Select,通过from selenium.webdriver.support.select import Select来导入。

    Select中提供几个用于定位的option的方法,下面看一下具体的方法

    主要把Select方法总结了一下分为三大类:

    1.选择列表

    • select_by_index(self, index)      #以index属性值来查找匹配的元素并选择;
    • select_by_value(self, value)           #以value属性值来查找该option并选择;
    • select_by_visible_text(self, text)     #以text文本值来查找匹配的元素并选择;
    • first_selected_option(self)               #选择第一个option 选项 
    # 针对按索引进行切换option属性
    Select(driver.find_element_by_id('id')).select_by_index(0)
    #针对按value进行切换option属性
    Select(driver.find_element_by_id('id)).select_by_value('abc')
    #针对按text文本进行切换option属性
    Select(driver.find_element_by_id('id')).select_by_visible_text ('text')
    

      

  • 相关阅读:
    SpringBoot04-web
    springboot03-日志功能
    SpringBoot02-自动配置原理
    SpringBoot02
    SpringBoot01
    八大排序算法
    SpringSecurity04
    SpringSecurity03
    SpringSecurity02
    SpringSecurity01
  • 原文地址:https://www.cnblogs.com/royfans/p/9934145.html
Copyright © 2011-2022 走看看