unknown property or method: `readyState'
HRESULT error code:0x80010108
The object invoked has disconnected from its clients. (NoMethodError)
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/browser.rb:603:in `method_missing'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/browser.rb:603:in `block in wait'
C:/Opt/Ruby/Ruby193/lib/ruby/1.9.1/timeout.rb:69:in `timeout'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/browser.rb:597:in `wait'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/container.rb:56:in `wait'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/container.rb:56:in `wait'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/element.rb:210:in `block in fire_event'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/element.rb:489:in `perform_action'
C:/Opt/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.3.0/lib/watir-classic/element.rb:210:in `fire_event'
C:/Jenkins/workspace/UI_Automation_Dev/trunk/Automation/ocelot/lib/ocelot/extensions.rb:400:in `method_missing'当我通过Jenkins在虚拟节点中执行时,我得到了上面的错误。当我在本地机器上手动运行相同的命令时,没有出现错误。这是抛出错误的代码块。
browser.frame(id: 'Iframe1').table(id: 'reviewHeader').td(id: 'RESAVE').when_present.click #clicking Save button
sleep(3) # Wait after Save so the 3rd party app. window closes
browser.window(title: /user/).use # Switch back to the main app window
browser.wait_for_page_load在这里,我单击保存按钮,这将关闭选项卡。然后,我睡了3秒钟。然后,我使用标题为“user”的窗口,并等待页面加载完成。单击“保存”按钮后出现错误;它没有切换到窗口。我甚至试着增加/减少睡眠时间,但不起作用。顺便说一下,我使用的是Watir Classic。
发布于 2017-01-22 11:48:54
重现异常的
查看异常发生的位置,我可以通过以下方式模拟异常:
<html>
<head><title>user</title></head>
<body><a href="popup.htm" target="_blank">popup</a></body>
</html><html>
<head><title>popup</title></head>
<body><a href="#" id="RESAVE">Re-save</a></body>
</html>使用手动interaction:运行以下Watir脚本的
browser = Watir::Browser.attach(:url, /popup/)
Watir::Browser::READYSTATES = {complete: 5}
browser.link.click # while this is running, which is 300 seconds, manually close the popup
#=> `method_missing': unknown property or method: `readyState' (NoMethodError)
#=> HRESULT error code:0x80010108
#=> The object invoked has disconnected from its clients.解决方案
异常发生在Browser#wait方法的这一部分,特别是@ie.readyState命令:
begin
while @ie.busy
sleep interval
end
until READYSTATES.has_value?(@ie.readyState)
sleep interval
end
until @ie.document
sleep interval
end
documents_to_wait_for = [@ie.document]
rescue WIN32OLERuntimeError # IE window must have been closed
@down_load_time = ::Time.now - start_load_time
return @down_load_time
end这段代码是用来拯救被关闭的窗口的。然而,我不确定为什么当我们得到一个NoMethodError时,它只包含WIN32OLERuntimeError。考虑到这段代码的历史,底层WIN32OLE可能随着时间的推移改变了它的返回类型,也可能只是另一个可能的异常。无论如何,猴子修补wait方法以同时处理NoMethodError将会解决这个异常。
require 'watir-classic'
module Watir
class Browser
def wait(no_sleep=false)
@xml_parser_doc = nil
@down_load_time = 0.0
interval = 0.05
start_load_time = ::Time.now
Timeout::timeout(5*60) do
begin
while @ie.busy
sleep interval
end
until READYSTATES.has_value?(@ie.readyState)
sleep interval
end
until @ie.document
sleep interval
end
documents_to_wait_for = [@ie.document]
rescue WIN32OLERuntimeError, NoMethodError # this is the only line modified
# IE window must have been closed
@down_load_time = ::Time.now - start_load_time
return @down_load_time
end
while doc = documents_to_wait_for.shift
begin
until READYSTATES.has_key?(doc.readyState.to_sym)
sleep interval
end
@url_list << doc.location.href unless @url_list.include?(doc.location.href)
doc.frames.length.times do |n|
begin
documents_to_wait_for << doc.frames[n.to_s].document
rescue WIN32OLERuntimeError, NoMethodError
end
end
rescue WIN32OLERuntimeError
end
end
end
@down_load_time = ::Time.now - start_load_time
run_error_checks
sleep @pause_after_wait unless no_sleep
@down_load_time
end
end
end如果问题只发生在单个脚本的这一步上,最安全的解决方案可能就是在一个地方抢救异常:
begin
browser.frame(id: 'Iframe1').table(id: 'reviewHeader').td(id: 'RESAVE').when_present.click #clicking Save button
rescue NoMethodError
# window was likely closed
endhttps://stackoverflow.com/questions/41756495
复制相似问题