# Re: Hpricot and xpath

**URL:** <https://www.ruby-forum.com/t/re-hpricot-and-xpath/145704>\
**Category:** Ruby\
**Created:** [August 13, 2008, 3:48am UTC](https://www.ruby-forum.com/t/re-hpricot-and-xpath/145704 "2008-08-13T03:48:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [August 13, 2008, 3:48am UTC](https://www.ruby-forum.com/t/re-hpricot-and-xpath/145704/1 "2008-08-13T03:48:08Z")

</div>

Subject: Re: Hpricot and xpath

> tag1.rb:6: undefined method `xpath’ for nil:NilClass (NoMethodError)  
> Do you see the nil in that line? Where is the nil coming from? Is the method  
> before the .xpath, on line 6, possibly returning a nil and not an Elem?

> After pondering that, switch ‘#header’ to ‘.header’!  
> Hi Phlip,  
> Thank you for your dot!!!  
> I follow your suggestion and change to ‘.header’ or “.header” instead  
> of “#header” and and it works. Ruby returns the tag’s path like this:  
> /tag1/tag2/div. But I see nowhere in the document about using “.” and  
> “#” in xpath() or css\_path(). Do I miss something in the docucment?  
> Li

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [August 13, 2008, 6:19am UTC](https://www.ruby-forum.com/t/re-hpricot-and-xpath/145704/2 "2008-08-13T06:19:48Z")

</div>

chen li wrote:

> I follow your suggestion and change to ‘.header’ or “.header” instead of “#header” and and it works. Ruby returns the tag’s path like this: /tag1/tag2/div. But I see nowhere in the document about using “.” and “#” in xpath() or css\_path(). Do I miss something in the docucment?

That’s just the thing. I studied the crap out of HTML, XHTML, and light  
CSS, and  
never learned until encountering assert\_select that CSS has its own  
query  
notation. Others with different career paths have learned nothing but -  
and they  
all assume you know the same things.

Hpricot can handle _light_ XPath, and can handle various CSS Selector  
notations.  
The documenters have all assumed that someone else taught you how they  
work. So  
google for “CSS Selector”, without x-ref’ing Hpricot!
