CSS3 Expression to XPath with Nokogiri

Posted in : ruby, nokogiri, and xpath

Nokogiri is such a wonderful library. Today we were trying to get the equivalent xpath query from a css expression and we found a fun way to do it automatically using Nokogiri.

Install nokogiri

First step is to have nokogiri installed

gem install nokogiri

Try it in irb

Open a terminal and start irb


Then try some fun translations

As you could see the XPath queries generated are a little bit verbose, but at least you can quickly get a working query if you’re more familiar with CSS3 expressions.

blog comments powered by Disqus