0
votes

I have a URL that I'm trying to extract information from. I want to navigate to a certain anchor tag that has a class value "_g3j", and click on it (it has a button role). I'm not sure how to access it and use the click method. That click would (ideally) link to another internal page, where I want to extract all links again.

Based on an earlier answer related to this, I've tried

 target_parent_div = b.divs.find { |div| div.a(class: "_g3j").exists? }  

As a sample, the value of the button I want to click looks like this:

  a class="_g3j" ajaxify="/ajax/browser/dialog/fanned_pages/?id=244944385603396&amp;showauxiliary=1" href="/browse/fanned_pages/?id=244944385603396&amp;showauxiliary=1" rel="dialog" aria-labelledby="u_0_1z" role="button" wotsearchprocessed="true"></a>  

I want to retrieve the href value given, click on it, and it opens another menu that has elements like so:

<a class="_8o _8t lfloat _ohe" href="https://www.facebook.com/bubblewitchsaga2?fref=pb" tabindex="-1" aria-hidden="true" wotsearchprocessed="true"><img class="_s0 _rw img" src="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/p40x40/10426523_405077716312722_7865103072715423222_n.png?oh=02338f513523fbf8e2d6a2f4bed13067&amp;oe=558DEDE1&amp;__gda__=1434976647_dafb1152b9d44f995c38b80afded1782" alt=""></a>    

In this second situation, how can I get the href here?
I apologize for the detailed question, but I'm still awaiting entry to the google group and I can't seem to find any documentation related to this.

1
Sorry, it is a bit difficult to understand which part you are stuck on. Is it just a general how to get an href attribute's value? Or are you looking for help in locating the second link?Justin Ko
I want to click on the href in the first link And then get the href front the second link. Sorry if this isn't very readabletvishwa107
I don't know how to get a link by class name. Is the href here an attribute?tvishwa107

1 Answers

1
votes

If you wanna click on link, what the problem?

require 'watir-webdriver'
browser = Watir::Browser.new
browser.goto 'your link'
browser.link(:class => '_g3j').click
browser.link(:class => '_8o').click

UPD: if first link open a new window, use someth like:

browser.windows.last.use do
  browser.link(:class => '_8o').click
  #Or you can take a list of links
  #And do with them all what you want
  browser.links #It's create array of links
end