【复习】selenium中用Xpath定位

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

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

【复习】selenium中用Xpath定位

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


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


4、轴定位(轴名称::节点名称)
ancestor:祖先节点包括父节点
parent:父节点
preceding-sibling: 选取当前节点以前的全部同级节点(html页面位置)
preceding:当前节点以前的全部节点(html页面位置)
following-sibling:当前节点以后的全部兄弟节点(html页面位置)
following:当前元素节点以后的全部节点(html页面位置)索引

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

相关文章
相关标签/搜索