博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
选择器-xpath
阅读量:4069 次
发布时间:2019-05-25

本文共 1519 字,大约阅读时间需要 5 分钟。

标签名

[@属性名=“属性值”]–标签名为*时查找所有标签

//*[@name='email']

在这里插入图片描述

绝对路径

以斜线“/”开始,“ /”代表着从根目录寻找

/html/head/meta[2]

在这里插入图片描述

相对路径

1.一般从HTML的中间部门随即开始

2.以双斜线开始“//”,“//”代表可以从html 中的任何一处开始寻找元素
3.比绝对路径要短
4.“/…”当前节点的父节点

//div[@class=‘form-group’]//input[@id=‘user-message’]

Contains

元素属性值包含

//*[contains(@id,"loginD")]

在这里插入图片描述

文本包含

//*[contains(text(),"邮箱帐号登")]

在这里插入图片描述

Starts-with

这个方法是针对一个属性是以什么开头的

//*[starts-with(@id,"loginD")]

在这里插入图片描述

and 和 Or

针对多属性组合定位

//input[@id="***" and @name=“xxx”]

//*[starts-with(@id,"loginD") and @class="loginUrs"]

在这里插入图片描述

//input[@id="***" or @name=“xxx”]

//*[@class="loginbox-title" or @class="loginUrs"]

在这里插入图片描述

Text

我们可以通过一个元素的文本内容来找到它

//*[text()="@163.com"]

在这里插入图片描述

兄弟关系

following-sibling 随后的兄弟元素

//*[@name=“email”]/following-sibling::span
在这里插入图片描述
preceding-sibling 之前的兄弟元素

//*[@name="email"]/preceding-sibling::label

在这里插入图片描述

***:: 表示当前节点的父节点。

父子child

选取当前节点的子元素,比较检查,一般不写

//*[@id="login-form"]/child::div
![在这里插入代码片](https://img-blog.csdnimg.cn/20200530090513447.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NoaXRvdTk4Nw==,size_16,color_FFFFFF,t_70)

父节点(根节点)parent

父节点

//*[@id="login-form"]/parent::*/parent::div同样效果//*[@id="login-form"]/../..

点

子元素descendant

descendant-or-self–包含自己

//[@id=“login-form”]/descendant-or-self::

//*[@id="login-form"]/descendant::div[@id="account-box"]

在这里插入图片描述

祖先元素ancestor

找到绝对路径上的所有元素

ancestor-or-self 包含自己:
//[@id=“login-form”]/ancestor-or-self::

//*[@id="login-form"]/ancestor::*

所有之前标签preceding

不包含自身标签

//*[@id="login-form"]/preceding::*

所有之后标签following

不包含自身标签

//*[@id="login-form"]/following::*

转载地址:http://htmji.baihongyu.com/

你可能感兴趣的文章
my pdfs
查看>>
framework Schedule Quartz
查看>>
IBM WebSphere Commerce Analyzer
查看>>
Unix + OS IBM Aix System Director
查看>>
Unix + OS IBM Aix FTP / wu-ftp / proftp
查看>>
my read work
查看>>
db db2 base / instance database tablespace container
查看>>
hd disk / disk raid / disk io / iops / iostat / iowait / iotop / iometer
查看>>
project ASP.NET
查看>>
db db2_monitorTool IBM Rational Performace Tester
查看>>
OS + Unix Aix telnet
查看>>
IBM Lotus
查看>>
Linux +Win LAMPP Tools XAMPP 1.7.3 / 5.6.3
查看>>
my read_university
查看>>
network manager
查看>>
OS + Linux Disk disk lvm / disk partition / disk mount / disk io
查看>>
RedHat + OS CPU、MEM、DISK
查看>>
net TCP/IP / TIME_WAIT / tcpip / iperf / cain
查看>>
script webshell jspWebShell / pythonWebShell / phpWebShell
查看>>
project site_dns
查看>>