Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby mechanize clicking divs

I'm trying to search a page for divs containing a specific class and then click on them. Each of these divs containing the class have a onclick event on them.

My current code looks like so,

home_page = agent.get('http://mysite.com')

home_page.search(".//div[@class='arrow up']").each do |i| 
  i.click
end

The div looks like so on the website.

<div class="arrow up" onclick="$(this).uparrow(u.config.places, null, event)" role="button" aria-label="uparrow" tabindex="0"></div>

Now there is obviously no click method for this because its a Nokogiri object, so I am here to ask is it possible for mechanize to click on a div like this? My current code can find all divs that match this class name, but I cannot figure out how to click on it.

like image 704
randy newfield Avatar asked Mar 24 '26 04:03

randy newfield


1 Answers

No there's no way to do that. You need to look at the onclick attribute and try to figure out what it's doing. That or use Watir.

like image 142
pguardiario Avatar answered Mar 26 '26 22:03

pguardiario



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!