zoukankan      html  css  js  c++  java
  • Selenium基础知识(六)下拉列表定位

    1、下拉列表定位

    要选择下拉列表中的元素,要先定位到,下拉列表元素,然后可以通过xpath去点击,表内内容

    例如,百度搜索-->百度设置-->搜索设置-->选择下拉列表框内"每页显示50条

    #先定位元素

    element = driver.find_element_by_id("nr") 

    #再通过元素下找xpath定位到内容,并点击

    element.find_element_by_xpath("//option[@value='50']").click()

    #当然如果,页面上只有一个下拉列表//option;也可以这样写:直接一步定位

    driver.find_element_by_xpath("//option[@value='50']").click()

    #输入selenium 搜索
        driver.find_element_by_id('kw').send_keys('selenium')
        driver.find_element_by_id('su').click()
    
        #移动到 设置
        element = driver.find_element_by_name('tj_settingicon')
        ActionChains(driver).move_to_element(element).perform()
    
        #单击,弹出的Ajax
        driver.find_element_by_link_text('搜索设置').click()
    
    
        #下拉列表处理
        element = driver.find_element_by_id("nr")
        element.find_element_by_xpath("//option[@value='50']").click()
  • 相关阅读:
    centos编辑文件显示行号
    16.1
    [整理]正睿划水记
    [题解]UVA1519 Dictionary Size
    [题解]CF323C Two permutations
    [题解]CF1527D MEX Tree
    P2216 [HAOI2007]理想的正方形
    CF858D Polycarp's phone book
    ABC214F substrings
    每天一点小知识-20210810
  • 原文地址:https://www.cnblogs.com/yhleng/p/7510235.html
Copyright © 2011-2022 走看看