I’m looking at the source code of Nokogiri::CSS, because I needed to convert CSS selectors to XPATH. After running a sample code and calling the xpath_for method, I see that it returns an array. Why is this? Are there any chances a CSS selector would return more than one xpath?
[18] pry(main)> Nokogiri::CSS.xpath_for 'div.divddy input:first'
=> ["//div[contains(concat(' ', @class, ' '), ' divddy ')]//input[position() = 1]"]
A CSS selector can contain multiple components separated by commas:
For example:
So presumably
xpath_forreturns an array in case you hand it a grouped selector. For example:Note that the returned array has length two in this case.