This forum is no longer active. Please post your questions to our new community site

Nokogiri has problems building child nodes

Subscribe to Nokogiri has problems building child nodes 2 post(s), 2 voice(s)

Avatar awstahl.hi5 1 post

Hi Folks – Having some trouble w/ Nokogiri & its handling of xpaths and
nodesets, wondering if anyone here knows about possible existing issues.

So I’m trying to access a form’s action URL so that I can construct my
own query string to GET via mechanize. I’ve tested just about every
possible xpath to get to the form’s action property, and Nokogiri is
behaving as if it doesn’t exist.

What I’ve discovered is that, once I hit a particular div tag, which
happens to be the parent node of the form, Nokogiri doesn’t see any of
the div’s children.

The page has HTML to this effect:

Note the form doesn’t have an ID or class by which to directly reference
it. Trying to access it like so:

sublnk = page.xpath(“//div[@id=‘app-#{code}’]”)

If I call children() on that, it’s empty. But the parent of this node
works fine, and Nokogiri constructs its children properly, including
containing the form as a child of “app-#{code}”:

sublnk =

Additionally, accessing the form directly via its index won’t work
either. It’s the second form on the page, so I’ve tried:

sublnk = page.xpath(“//form2/@action”)

…and still get nothing. It’s as if this node just doesn’t exist to
Nokogiri, even though it clearly does when it’s a child. So am I doing
something wrong? How come //div[@id=‘app-#{code}] doesn’t have any
children? Is there a bug in Nokogiri which prevents it from accessing
the form node? Why won’t any xpath to the form work?!? Please help me
stop banging my head on my desk.


Avatar danoo Administrator 81 post(s)


I recommend you to post a question on Nokogiri mailing list. I have tested the sample code from page and everything works fine.

Please let us know once you figure what the problem is.