简体   繁体   中英

error when clicking a link using ruby/watir

I am new to ruby/watir and am getting an error when trying to click on a link. The error is:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-classic/elemen
t.rb:328:in `assert_exists': Unable to locate element, using {:tag_name=>["a"],
:id=>"My Link"} (Watir::Exception::UnknownObjectException)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-c
lassic/element.rb:474:in `perform_action'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-c
lassic/element.rb:354:in `click!'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-c
lassic/element.rb:157:in `click'
        from Login.rb:22:in `<main>'

The link that I am trying to click looks like this:

<TD><DIV id=div style="DISPLAY: inline"><A id=Hyperlink href="javascript:RunFullScreen('myURL')">My Link</A></DIV>

Also, I tried to write out all links on the page using 'puts', but nothing was written out when the script finished I used this code to write out the links (not sure if this is correct or not):

browser.links.each {|link| puts link.attribute_value("text") if link.visible?}

The error says tat you tried to find an object with the following properties: {:tag_name=>["a"], :id=>"My Link"} , but you have show us HTML code with A id=Hyperlink . So to find out that HTML you need to specify properly its attributes:

 @b.element :tag_name => 'a', :id => 'Hyperlink'

or

 @b.a :id => 'Hyperlink'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM