使用ruby / watir单击链接时出错

时间:2022-01-21 00:29:59

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

我是ruby / watir的新手,在尝试点击链接时遇到错误。错误是:

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):

此外,我尝试使用'puts'写出页面上的所有链接,但是当脚本完成时没有写出任何内容我使用此代码写出链接(不确定这是否正确):

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

1 个解决方案

#1


1  

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:

错误说明你试图找到一个具有以下属性的对象:{:tag_name => [“a”],:id =>“我的链接”},但你已经向我们展示了A id = Hyperlink的HTML代码。因此,要找出HTML,您需要正确指定其属性:

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

or

 @b.a :id => 'Hyperlink'

#1


1  

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:

错误说明你试图找到一个具有以下属性的对象:{:tag_name => [“a”],:id =>“我的链接”},但你已经向我们展示了A id = Hyperlink的HTML代码。因此,要找出HTML,您需要正确指定其属性:

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

or

 @b.a :id => 'Hyperlink'