0

Is there a way to use XPath in Ruby without specifying the tag?

For example, I want to get all elements whose class contains 'trow1'. Not just tr, as the code below is doing:

doc.xpath("//tr[contains(@class,'trow1')]")
Henley Chiu
  • 17,838
  • 29
  • 110
  • 187
  • Please read "[mcve]". It really helps when you supply the minimum input data to demonstrate the problem you're having. As is, you're asking us to create that data which will be different for everyone trying to help you. – the Tin Man Dec 06 '16 at 21:49
  • This isn't a Ruby or Nokogiri question as much as it is an XPath question. You can find more information on the internet about this by searching for "`xpath all nodes containing attribute`". You'd find it much easier to solve the question if you used the CSS selector `'.trow1'`. This is one of the times that knowing both CSS and XPath helps. – the Tin Man Dec 06 '16 at 21:58
  • of course a css selector is the best choice (obviously) but what if the class is " trow1" (yes a space before trow1). the css selextor doesnt always extract it – Henley Chiu Dec 07 '16 at 03:36

0 Answers0