1

I tried this:

page.find("#parentNode").first(".childClass").click

but got the error: NoMethodError:undefined method 'click' for nil:NilClass

How can I click childNode1 or childNode2

<div id="parentNode">
     <div id="childNode1" class="childClass">
         <img src="path img1"></img>
     </div>
     <div id="childNode2" class="childClass">
        <img src="path img2"></img>
     </div>
 </div>
Bryan Ash
  • 4,385
  • 3
  • 41
  • 57
beginerdeveloper
  • 785
  • 4
  • 17
  • 43
  • what error did you get? – Bryan Ash Sep 30 '14 at 13:34
  • Doesn't `page.find('#childNode1').click` work? I'm not surprised you're getting an error as none of the IDs or classes you're trying to match appear in the HTML you show. – pjmorse Sep 30 '14 at 13:35
  • 1
    NoMethodError:undefined method `click' for nil:NilClass – beginerdeveloper Sep 30 '14 at 13:36
  • This question might help http://stackoverflow.com/questions/602168/in-css-what-is-the-difference-between-and-when-declaring-a-set-of-styles – Bryan Ash Sep 30 '14 at 13:47
  • i update my code pls check again – beginerdeveloper Sep 30 '14 at 13:55
  • Since your username is 'beginerdeveloper', I should point out an important debugging strategy: work incrementally. You have a long chain of methods, and the exception is saying you can't call the `click` method on `nil:NilClass`. That means that `page.find("#parentNode").first(".childClass")` is returning `nil`. That is, in itself, a chain of methods, so just start by calling `page.find("#parentNode")` and check the result, and build up your function from there. – aceofbassgreg Oct 01 '14 at 01:38

1 Answers1

1

Use click method: find("#childNode1").click

Click