Ruby mechanize clicking divs

900 views Asked by At

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.

1

There are 1 answers

1
pguardiario On BEST ANSWER

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.