zoukankan      html  css  js  c++  java
  • python3+selenium3自动化5——元素定位xpath详解

    一、常规定位
    1、通过id定位
    driver.find_element_by_xpath("//*[@id='kw']").send_keys('哈啰')

    2、通过tag(标签)定位
        *号是匹配任何标签
        driver.find_element_by_xpath("//*[@id='kw']")
        也可以用指定标签定位
        driver.find_element_by_xpath("//input[@id='kw']")
        
    3、通过calss定位
        driver.find_element_by_xpath("//*[@calss='s_ipt']").send_keys('哈啰')
    
    4、通过name定位
        driver.find_element_by_xpath("//*[@name='wd']").send_keys('哈啰')
    

    二、其他属性定位
    1、其他属性
    driver.find_element_by_xpath("//*[@autocomplete='off']").send_keys('哈啰')

    2、多个属性组合
        driver.find_element_by_xpath("//*[@type='test' and @name=‘wd’]").send_keys('哈啰')
    
    3、绝对路径(最好不要使用绝对路径定位方式)
    

    三、 文本属性
    语法:.//[test()='文本内容']
    driver.find_element_by_xpath("//
    [test()='我的标签']")

    四、层级关系
    driver.find_element_by_xpath("//*[@id='nr']/option[3]")(定位百度搜索选相框)

    五、模糊匹配
    1、contains模糊匹配text
    driver.find_element_by_xpath("//a[contains(text(),‘哈啰’)]").click()

    2、模糊匹配某个属性
        driver.find_element_by_xpath("//input[contains(@class,‘s_ip’)]").click()
  • 相关阅读:
    支付宝支付
    七牛云存储介绍
    ubuntu开发机初始化
    Unity3D 正六边形,环状扩散,紧密分布,的程序
    Unity属性的封装、继承、方法隐藏
    DateTime.Now的一些用法
    [转] 增强现实 colAR Mix 浅析
    [转] Vuforia AR 中的阴影与浮现效果
    网址整理
    [转] 如何使用unity Vs来进行断点调试
  • 原文地址:https://www.cnblogs.com/jiliangceshi/p/12779254.html
Copyright © 2011-2022 走看看