As pointed out in this answer , you can simply create a new Mechanize::Form object using your Nokogiri::XML::Element , obtained through Mechanize::Page#search or Mechanize::Page#at :
a = Mechanize.new page = a.get 'https://stackoverflow.com/'
Note. You must provide the Mechanize object and the Mechanize::Page object to the constructor so that it can submit the form. Otherwise, it will be just a Mechanize::Form object with no context.
It seems that there is no central utility function for converting Nokogiri::XML::Element to Mechanize elements, and conversions are performed where they are needed. Therefore, when writing a method that searches for a document using CSS or XPath and returns Mechanize elements, if applicable, the node type requires a fairly large commutation register. Not quite what I imagined.
source share