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

来源:互联网 发布:直播cms 编辑:程序博客网 时间:2024/04/29 06:46
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')]"

0 0
原创粉丝点击