我的HTML看起来像这样:
<html>
<head></head>
<body>
<a class="xyxyxy" href="" onclick="window.open('https://iogossip.com/Disclosure.pdf', '_blank')">DISCLOSURE</a>
</body>
</html>
我需要把&#39; https://iogossip.com/Disclour.pdf&#39;到屏幕。或者把整个事情放在&#34; window.open(&#39; https://iogossip.com/Disclosure.pdf&#39;,&#39; _blank&#39;)&#34;到屏幕。 当我这样做时:
puts browser.a.onclick
我收到此错误:
NoMethodError: undefined method `onclick' for #<Watir::Anchor:0x29fc448>
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.2/lib/watir
-webdriver/elements/element.rb:553:in `method_missing'
from (irb):6
from C:/Ruby193/bin/irb:12:in `<main>'
感谢,
答案 0 :(得分:2)
您可以使用Element#attribute_value
方法获取属性值(watir 2.0.3应该支持):
puts browser.a.attribute_value('onclick')
#=> "window.open('https://iogossip.com/Disclosure.pdf', '_blank')"
答案 1 :(得分:0)
你的代码对我来说很好。
尝试: href =“#”