zoukankan      html  css  js  c++  java
  • Python自动化中的元素定位xpath(二)

    1、Xpath元素定位

    1)ele = b.find_element_by_xpath(‘/html/body/from/input[1]’)

    2)Ele = b.find_element_by_xpath(‘//input[2]’) 定位第二个input

    3)Ele = b.find_element_by_xpath(‘//from//input’) 定位from里面的input

    4)Ele = b.find_element_by_xpath(‘//input[@id]’) 定位input里面含有id

    5)Ele = b.find_element_by_xpath(‘//input[@name=”firstname”]’)

    6)Ele = b.find_element_by_xpath(‘//*[count(input)=2]’) 定位具有两个input的元素(*为所有元素)

    7)Ele = b.find_element_by_xpath(‘//*[count(input)=2/..]’)定位具有两个input的元素的父节点

    8)Ele = b.find_element_by_xpath(‘//*[local-name()=”input”]’)定位标签为input的元素

    9)Ele.tag_name      显示定位的标签名称

    10)ele.get_attribute(‘name’) 显示定位到的属性名称

    11)Ele = b.find_element_by_xpath(‘//*[starts-with(local-name(),”i”)]’)定位所有tagi开头的元素

    12)Ele = b.find_element_by_xpath(‘//*[contains(local-name(),”i”)]’)定位所有tag包含i的元素

    13)Ele = b.find_element_by_xpath(‘//from//*[contains(local-name(),”i”)]’)定位在from里面所有tag包含i的元素

    14)Ele = b.find_element_by_xpath(‘//from//*[contains(local-name(),”i”)][last()]’)定位在from里面所有tag包最后一个含i的元素

    15)Ele = b.find_element_by_xpath(‘//from//*[contains(local-name(),”i”)][last()-1]’)定位在from里面所有tag包倒数第二个含i的元素

    16)Ele = b.find_element_by_xpath(‘//*[string-length(local-name())=5]’)定位所有tag里面长度为5的元素

    17)Ele = b.find_element_by_xpath(‘//title | //input’) 多个路径查找

  • 相关阅读:
    2.16.8.内核启动的C语言阶段5
    2.16.7.内核启动的C语言阶段4
    2.16.6.内核启动的C语言阶段3
    2.16.5.内核启动的C语言阶段2
    JAVA_SE基础——34.static修饰成员变量
    JAVA_SE基础——33.this关键字的练习
    JAVA_SE基础——32.this关键字调用本类的构造方法
    JAVA_SE基础——31.this关键字
    JAVA类的方法调用和变量(全套)
    JAVA_SE基础——30.构造代码块
  • 原文地址:https://www.cnblogs.com/yanmou/p/10678075.html
Copyright © 2011-2022 走看看