0

I need to find every HTML div which class starts with mod mod-article-tile mod-article-tile--tertiary. I found various explanations for XPath Contains, and can't seem to figure it out. Here is an example: My code that finds only the divs with this exact class (tested and works): '//*[@class="mod mod-article-tile mod-article-tile--tertiary"]/@id'

What I think was my closest guess: '//*contains(@class, "mod mod-article-tile mod-article-tile--tertiary")/@id'

If anyone could explain why it doesn't work and how I can fix it, that'd be great. XPath is still pretty confusing with the whole symbol syntax.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
JasperMW
  • 465
  • 3
  • 7
  • 22

1 Answers1

2

You forgot to put the contains() in a predicate ([ ])...

//*[contains(@class, "mod mod-article-tile mod-article-tile--tertiary")]/@id

Note though that those classes will still need to appear in that order to match. See the answers in this question for more info/help.

Daniel Haley
  • 51,389
  • 6
  • 69
  • 95