Reputation: 97
I have the following element on a page, which I'm using xpath to locate;
<meta name="robots" content="noindex, follow">
What I'd like to do is test that the content part of the element contains "noindex", and ignore the "follow" part of the element.
Previously I've used css to test this kind of thing using something along the lines of content*="noindex", but because of this particular page structure I'm not able to use css.
So (css) head > meta:nth-child(60)[content*="noindex"]
works (but this is inflexible as the element location can change) but (xpath) //meta[@name="robots" and @content*="noindex"]
doesn't.
Any help would be greatly appreciated.
Thanks.
Upvotes: 0
Views: 72
Reputation: 163322
Since you didn't specify a particular version of XPath: from XPath 2.0 you can use regular expressions. For example
//meta[@name="robots"][tokenize(@content, ",") = "noindex"]
If you want to do this in the browser you'll need to install a third-party XPath library such as Saxon-JS.
Upvotes: 0
Reputation: 14135
Use the below xpath.
//meta[@name="robots"][contains(@content,"noindex")]
If you want to use starts-with
below is the syntax.
//meta[@name="robots"][starts-with(@content,"noindex")]
Upvotes: 2