tags:

views:

54

answers:

3

Hi all,

I'm trying to retrieve the "onclick" attribute value from the below link:

<a onclick="test" href="myurl">aaa</a>

Using link.href works fine (So I know link is the correct object) however when using link.attribute_value("onclick") what I get is a win32 object (puts shows #<WIN32OLE:0x2cbdf10> instead of the "test" string).

Could someone help me get the onclick value please?
Thanks

+2  A: 

If you don't get a neater solution, and it's a one off(If you can make sure the development process keeps this kind of testing in mind next time).Try:

onclick_value=browser.html[ %r{<a onclick="(.*?)" href="myurl">}mi, 1 ]
Keith Hughes
A: 

Tested on Mac with watir-webdriver gem driving Firefox:

browser.link(:href => "myurl").html.split('"')[3]
# => "myurl"

Tested on Windows with watir gem driving IE:

browser.link(:href => /myurl/).html.split('"')[1]
# => "myurl"
Željko Filipin
A: 

This worked for me (Windows 2003, ruby 1.8.7, watir 1.6.5):

browser.link(:href => /myurl/).attribute_value("onclick")
# => "test"
Željko Filipin