zoukankan      html  css  js  c++  java
  • Selenium+python --定位下拉列表框并选取内容

    follow yoyo

    定位下拉列表并选取内容

    # coding:utf-8
    from selenium import webdriver
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium .webdriver.support.select import Select

    driver = webdriver.Firefox()
    driver.get("https://baidu.com")
    driver.implicitly_wait(20)

    # 鼠标移动到设置按钮
    mouse = driver.find_element_by_link_text("设置")
    ActionChains(driver).move_to_element(mouse).perform()
    driver.find_element_by_link_text("搜索设置").click()

    # 方法一:定位到下拉框,再点击选项
    # s = driver.find_element_by_id("nr")
    # s.find_element_by_xpath("//option[@value='50']").click()
    driver.find_element_by_id("nr").find_elements_by_xpath("//option[@value='50']").clear()

    # 方法二:使用xpath/css定位
    driver.find_elements_by_xpath("//*[@id='nr']/option[2]").click()

    # 方法三:使用Select模块by index
    s = driver.find_element_by_id("nr")
    Select(s).select_by_index(2)

    # select by value
    Select(s).select_by_value("20")

    # select by text
    Select(s).select_by_visible_text("每页显示20条")


  • 相关阅读:
    函数
    数组
    类的例题
    异常语句
    类的学习
    for的穷举、迭代
    for循环
    switch case
    反相器,扇入扇出
    T触发器,JK触发器的verilog实现
  • 原文地址:https://www.cnblogs.com/shanliguniang/p/10654030.html
Copyright © 2011-2022 走看看