zoukankan      html  css  js  c++  java
  • python+selenium 对下拉框的处理

     

    一:固定选择某一选项。利用二次定位的方法,先定位该下拉框,然后定位具体的选项

    rzmd = driver.find_element_by_id("rzmd")

    rzmd.find_element_by_xpath("//option[@value='luhff5fclyys95vz_继续教育']").click()

    二:随机选择某一选项。该方法利用的也是重复定位的方法,只是二次定位时定位到的是一组option,通过random.choice()方法随机选择

    select = driver.find_element_by_id("rzmd")

    alloptions = select.find_elements_by_tag_name("option")

    readom.choice(alloptions).click()

    三:遍历下拉选项。get_attribute()方法返回指定属性名的属性值

    select = driver.find_element_by_id("rzmd")

    alloptions = select.find_elements_by_tag_name("option")

    for option in alloptions:

      print "value is:%s" % option.get_attribute("value")

      option.click()

     

  • 相关阅读:
    equals方法
    StringBudilde
    日期
    system
    File类
    calender
    stringbuilder tostring
    File的三种构造方法
    Java入门——day52
    Java入门——day53
  • 原文地址:https://www.cnblogs.com/sunjump/p/7273654.html
Copyright © 2011-2022 走看看