您好我正在使用ruby + watir + selenium来自动登录页面。 所以按钮的html部分是:
<paper-button id="ok" class="style-scope login-window x-scope paper-button-0" role="button" tabindex="0" animated="" aria-disabled="false" elevation="0">OK</paper-button>
我的代码是:
@browser.text_field(:xpath => ("(//input[@id='input'])[2]")).send_keys('user')
@browser.text_field(:xpath => ("(//input[@id='input'])[3]")).send_keys('pass')
sleep 10
@browser.button(:id => ("ok")).click
我试过这个:
@browser.button(:class => 'style-scope login-window x-scope paper-button-0').click
@browser.button(:id => 'ok').click
这些回报:
C:\Komodo_files>ruby test.rb
Loaded suite test
Started
E
====================================================================================================
Error: test_login(login): Watir::Exception::UnknownObjectException: element located, but timed
out after 30 seconds, waiting for #<Watir::TextField: located: true; {:xpath=>"(//input[@id='input'
])[2]", :tag_name=>"input"}> to be present
C:/Ruby24/lib/ruby/gems/2.4.0/gems/watir-6.8.4/lib/watir/elements/element.rb:622:in `raise_present'
C:/Ruby24/lib/ruby/gems/2.4.0/gems/watir-6.8.4/lib/watir/elements/element.rb:662:in `rescue in eleme
nt_call'
C:/Ruby24/lib/ruby/gems/2.4.0/gems/watir-6.8.4/lib/watir/elements/element.rb:673:in `element_call'
C:/Ruby24/lib/ruby/gems/2.4.0/gems/watir-6.8.4/lib/watir/elements/element.rb:283:in `send_keys'
test.rb:27:in `test_login'
24: def test_login
25: @browser.goto "http://qa.application.com"
26: sleep 20
=> 27: @browser.text_field(:xpath => ("(//input[@id='input'])[2]")).send_keys('user'
)
28: @browser.text_field(:xpath => ("(//input[@id='input'])[3]")).send_keys('pass')
29: sleep 10
30: @browser.button(:id => ("ok")).click
====================================================================================================