Selenium 2.0 Webdriver & Ruby, link element methods other than .text? Navigate.to links in array? Selenium 2.0 Webdriver & Ruby, link element methods other than .text? Navigate.to links in array? selenium selenium

Selenium 2.0 Webdriver & Ruby, link element methods other than .text? Navigate.to links in array?


I was not sure of the format for use with the attribute method, but after some experimenting I was able to move past this step.

@countries = Array.new

@browser.navigate.to "http://www.testingdomain{$env}.com/global"

@browser.find_elements(:xpath, "//table[@class='global-list']//a").each do |link|
text = link.attribute("text")
href = link.attribute("href")
@countries << [text, href]
end #links
`@countries.uniq! #DEBUG for false CMS content


Looks like you found your answer to your question on your own.

Indeed, element.attribute allows you to pull any HTML attribute a tag could possibly have. Thus, since you were wanting to pull the URL of the element, you used element.attribute('href') to return the element's href="" attribute. The same can be done for any other attributes, including class, id, style, etc.