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

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')]"

你可能感兴趣的:(selenium)