From: Robert Klemme Date: 2012-01-19T00:50:29+09:00 Subject: Re: Finding a

text which contains
On Tue, Jan 17, 2012 at 6:31 PM, Brad Symons wrote: > I am trying to locate using exists? a

in my page which is seperated > by two
tags, as shown below. In the IRB, these show as \n when I > retrieve the text, but using that same value to locate it is not > working. > > The html: >

The Promotional Code you have entered has not been > recognised.

Please check your Promotional Code and try again.

You can do this with XPath expression "//p[br]": Preparation, parsing HTML into a DOM: $ irb -r nokogiri irb(main):001:0> doc = '

empty

foo
bar' => "

empty

foo
bar" irb(main):002:0> dom = Nokogiri.HTML(doc) => #, #]>, #, #, #]>]>]>]>]>

's with nested
: irb(main):007:0> dom.xpath('//p[br]') => [#, #, #]>] irb(main):008:0> dom.xpath('//p[br]').map &:to_s => ["

foo
bar

"] All

's: irb(main):009:0> dom.xpath('//p').map &:to_s => ["

empty

\n", "

foo
bar

"] Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/