|
For ID
- //div[contains(@id,"content-body")]//p #to Select all Paragraphs
- //div[contains(@id,"content-body")]//p//text() # To Select all text in Paragraphs
复制代码
For Class
- //*[contains(@class,"content-body")//p
- //div[contains(@class,"content-body")]//p//text()
复制代码
For class in class
- //*[contains(@class,"content-body") and contains(@class,"another-sub-content-body")]//p//text()
复制代码
- //get text
- var iTotal=getElementByXpath("//td[contains(@id,objID)]//a//div[1]").innerText
- var sName=getElementByXpath("//td[contains(@id,objID)]//a//div[2]").innerText
- //console.log(iTotal,sName);
- $("#iTotal").html(iTotal);
- $("#sName").html(sName);
- function getElementByXpath(path) {
- return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
- }
复制代码 |
|