首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未知的属性或方法:` `readyState‘HRESULT错误代码:0x80010108调用的对象已与其客户端断开连接。(NoMethodError)

未知的属性或方法:` `readyState‘HRESULT错误代码:0x80010108调用的对象已与其客户端断开连接。(NoMethodError)
EN

Stack Overflow用户
提问于 2017-01-20 13:08:45
回答 1查看 139关注 0票数 0
代码语言:javascript
复制
    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在虚拟节点中执行时,我得到了上面的错误。当我在本地机器上手动运行相同的命令时,没有出现错误。这是抛出错误的代码块。

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

发布于 2017-01-22 11:48:54

重现异常的

查看异常发生的位置,我可以通过以下方式模拟异常:

  1. 使用超文本标记语言创建和打开窗口(这是主窗口):

代码语言:javascript
复制
<html>
  <head><title>user</title></head>
  <body><a href="popup.htm" target="_blank">popup</a></body>
</html>

  1. 使用文件名"popup.htm“和超文本标记语言(这是弹出窗口)创建和打开窗口:

代码语言:javascript
复制
<html>
  <head><title>popup</title></head>
  <body><a href="#" id="RESAVE">Re-save</a></body>
</html>

使用手动interaction:运行以下Watir脚本的

代码语言:javascript
复制
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命令:

代码语言:javascript
复制
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将会解决这个异常。

代码语言:javascript
复制
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

如果问题只发生在单个脚本的这一步上,最安全的解决方案可能就是在一个地方抢救异常:

代码语言:javascript
复制
begin
  browser.frame(id: 'Iframe1').table(id: 'reviewHeader').td(id: 'RESAVE').when_present.click #clicking Save button
rescue NoMethodError
  # window was likely closed
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41756495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档