Maheshkumar.J Maheshkumar.J - 5 months ago 10
Ruby Question

How do i resolve this error?undefined method `at_css' for #<Mechanize::Page:0xb4b76434>

NoMethodError Exception: undefined method `at_css' for #
At the time of run this code,
result.at_css("body").text

Answer

You need to call the root method on the Mechanize::Page object first:

page = Mechanize.new.get("http://....")
page.root.at_css('...')

root will return a Nokogiri::HTML::Document, which implements the at_css method.