您的位置:首页 > 其它

通过chrome利用xpath定位页面元素

2017-03-07 14:07 821 查看
1、document.getElementById("btn-edit").click()

参考:http://www.cnblogs.com/zuola/p/5750018.html

2、function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

getElementByXpath('//*[@id="about"]/div/div[2]/a')

3、查找描述模糊匹配:
http://stackoverflow.com/questions/5925567/xpath-with-regex-match-on-an-attribute-value
(/*/*/event[contains(@description, ' doubles ')]

or
/game/team/event[matches(@description, ' doubles ')]/@description

/game/team/event[matches(@description, '^.*?doubles.*$')]/@description

/game/team/event[contains(@description, ' doubles ')]/@description


4、Firefox自带函数模糊匹配:
$x("//*/tbody[contains(@id, 'normalthread')]"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: