美文网首页
UI自动化01 css selector&xpath

UI自动化01 css selector&xpath

作者: 6c0fe9142f09 | 来源:发表于2018-09-10 11:12 被阅读6次
练习软件安装
1.xpath

通过路径解析XML的一种格式
写xpath是在做一个缩减范围的过程

//*   # 定位当前html的所有元素
//input  # 由全部元素缩减到指定元素类型

# 标签+属性方式进行定位
//select[@name="city" and @multiple="multiple" and @size="4"]

# 取反定位
//div[@class='driver']/div[@class="inner"]/input[not(@placeholder="请通过ID定位元素")]

# 层级定位,角标中的值代表:获取body中所有div在第二个位置的标签
# 获取body下的第二个div
//body/div[2]
css selector

通过路径解析HTML的一种格式

#i1  #通过id进行定位
.classname  #通过class定位
input  #通过标签进行定位

# 属性的模糊匹配 开头^=
input[placeholder^="请通过ID定"]

# 属性的模糊匹配 结尾$=
input[placeholder$="过ID定位元素"]

# 属性的模糊匹配 任意
input[placeholder*="元素"]

# 属性的取反
div:not([id="wrapper"])
  • 层级获取
# first-child
body>:first-child
# last-child
body>:last-child
# nth-child(x)
body>:nth-child(3)

相关文章

网友评论

      本文标题:UI自动化01 css selector&xpath

      本文链接:https://www.haomeiwen.com/subject/tmurgftx.html