zoukankan      html  css  js  c++  java
  • selenium的关于选择框的定位

    # coding:utf-8
    from selenium import webdriver
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support.select import Select
    import time
    driver = webdriver.Chrome()
    driver.get('http://www.baidu.com')
    driver.implicitly_wait(10)
    mouse = driver.find_element_by_link_text(u'设置')
    ActionChains(driver).move_to_element(mouse).perform()
    driver.find_element_by_link_text(u'搜索设置').click()
    time.sleep(1)
    '''第一种方式, 直接用xpath定位到要选中的项
    driver.find_element_by_xpath('//*[@id="nr"]/option[3]').click()
    '''

    '''第二种方式,使用select选中器
    sel = driver.find_element_by_xpath('//*[@id="nr"]') #先定位到选择框
    time.sleep(1)
    Select(sel).select_by_index(2) #根据选择框的索引去选中
    Select(sel).select_by_visible_text('每页显示50条') #根据text值来选中
    Select(sel).select_by_value('50') #根据walue值来选中
    '''

    备注:若是非正规的选择器,则直接使用第一种方式,或者是按照人工操作顺序,先点选择框,后点需要选中的元素
    人不可无方向
  • 相关阅读:
    QT QT程序初练
    Linux Shell编程三
    Linux Shell编程二
    git操作
    git push命令
    Zabbix全方位告警接入-电话/微信/短信都支持
    CentOS 7安装TigerVNC Server
    MySQL各版本的区别
    MariaDB Galera Cluster 部署
    MySQL高可用方案MHA的部署和原理
  • 原文地址:https://www.cnblogs.com/yueyanru/p/9393661.html
Copyright © 2011-2022 走看看