【复习】selenium中用Xpath定位

一、基础属性定位
id/class/name
百度一下按钮://input[@id="su"]*

text()定位
更多产品链接定位://*[text()="更多产品"]

【复习】selenium中用Xpath定位

二、索引过滤
当定位出现多个兄弟结果时,可以索引过滤,坐标从1开始,最后用last()
新闻链接://a[@class="mnav"][1]
学术链接 //a[@class="mnav"][last()]


三、逻辑运算定位
【复习】selenium中用Xpath定位
新闻链接://a[@class="mnav" and text()="新闻"]


四、轴定位(轴名称::节点名称)
ancestor:祖先节点包括父节点
parent:父节点
preceding-sibling: 选取当前节点之前的所有同级节点(html页面位置)
preceding:当前节点之前的所有节点(html页面位置)
following-sibling:当前节点之后的所有兄弟节点(html页面位置)
following:当前元素节点之后的所有节点(html页面位置)

例:查找地图的兄弟节点新闻://a[@name="tjtrmap"]/parent::div/[text()="新闻"]

猜你喜欢

转载自blog.51cto.com/11926720/2481077