Forum: RSpec nokogiri selector help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
387fb00ef9d6d523d43018d9c81ab36b?d=identicon&s=25 Jonathan Linowes (Guest)
on 2009-01-24 06:12
(Received via mailing list)
hiya,

i want the selector that would return a <tr> of a table if any td
contains some text, so i can use it in click_link_within

e.g. When I click the "show" link within the row containing
"user@example.com"


When /^I click the "(.+)" link within the row containing "(.+)"$/ do |
link, text|
  selector = ??
  click_link_within  selector, link
end


-----------
and lets say the response contains

...
<div class="table-container">
   <table>
     <tbody>
       <tr>...</tr>
       <tr>
         <td><a href="/posts/14">show</a></td>
         <td>foo</td>
         <td>bar</td>
         <td>user@example.com</td>
         <td>baz</td>
       </tr>
       <tr>...</tr>
     </tbody>
   </table>
</div>
...
F86901feca747abbb5c6c020362ef2e7?d=identicon&s=25 Zach Dennis (zdennis)
on 2009-01-25 18:15
(Received via mailing list)
On Sat, Jan 24, 2009 at 12:05 AM, Jonathan Linowes
<jonathan@parkerhill.com> wrote:
> text|
>        selector = ??
>        click_link_within  selector, link
> end

You can use an XPath selector to find the parent. Try:

selector = "//table//tr//td[contains(.,'user@example.com')]//.."

>      <tr>
> ...
>

--
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
387fb00ef9d6d523d43018d9c81ab36b?d=identicon&s=25 Jonathan Linowes (Guest)
on 2009-01-31 04:01
(Received via mailing list)
On Jan 25, 2009, at 11:58 AM, Zach Dennis wrote:

>>
> selector = "//table//tr//td[contains(.,'user@example.com')]//.."
hi Zach,

that works as a selector when I do
         doc = Nokogiri::HTML.parse( response.body )
         doc.xpath(selector)
returns the correct dom elements

but when used with click_link_within I get the error

Nokogiri::CSS::SyntaxError Exception: unexpected '//' after ''
F86901feca747abbb5c6c020362ef2e7?d=identicon&s=25 Zach Dennis (zdennis)
on 2009-02-04 05:10
(Received via mailing list)
On Fri, Jan 30, 2009 at 9:45 PM, Jonathan Linowes
<jonathan@parkerhill.com> wrote:
>>> some text, so i can use it in click_link_within
>>> end
> returns the correct dom elements
>
> but when used with click_link_within I get the error
>
> Nokogiri::CSS::SyntaxError Exception: unexpected '//' after ''
>

Sorry for the late reply, but this is a bug in webrat not a nokogiri
issue. I've created a ticket for it at lighthouse:

http://webrat.lighthouseapp.com/projects/10503-web...


--
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
4ad162dfe21860c259272f8e004b9753?d=identicon&s=25 Tom Ten Thij (tomtt)
on 2009-03-10 15:14
> Sorry for the late reply, but this is a bug in webrat not a nokogiri
> issue. I've created a ticket for it at lighthouse:
>
> 
http://webrat.lighthouseapp.com/projects/10503-web...

I wrote an ugly duckpunch that fixes the error for now. I have submitted
it as a comment on the ticket
This topic is locked and can not be replied to.