xpath cheet sheet

yentotexbof
Oct 30, 2020
*Attributes are represented by "@" in XPath
/html/body/div/span[@class='value']
//span[@class='regular_price']

the writing below is called descendant-or-self, and you can refer to all the dom elements of that html.

//img[contains(@class, 'image')]

Whether it can be taken with a perfect partial match.

//div[contains(text(), 'item')]

When you want to specify an element containing the characters “Product number” from this HTML. You can also use the not operator like

//img[not(contains(@src, ‘main’))]/@src

//*[text()="searchkeyword"]/following-sibling::p[2]

Gets the penultimate p element of that element as seen from the parent element.

//td[not(.=preceding::td)]

Of all the elements, select the one that does not match the tag and content among all the elements before the child element. character *(“.”) in XPath is called the “context item expression” because it refers to the context item. All td elements are shown here.

  • Works only on child nodes (tags). If you want to specify attributes with wildcards, use @ *.

--

--

yentotexbof

information science & technology. threat hunting. Researcher of Internet Assigned Numbers Authority