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’) 多个路径查找

  • 相关阅读:
    P1536 村村通 题解
    P1551 亲戚题解
    P1185 绘制二叉树 题解
    P3884 [JLOI2009]二叉树问题
    P1087 [NOIP2004 普及组] FBI 树
    P1305 新二叉树题解
    P1229 遍历问题
    P1030 [NOIP2001 普及组] 求先序排列题解
    P1827 [USACO3.4]美国血统 American Heritage 题解
    深度优先搜索dfs 讲解教程
  • 原文地址:https://www.cnblogs.com/yanmou/p/10678075.html
Copyright © 2011-2022 走看看