由waitr的execute_script引起的OLE错误代码80020101

时间:2012-12-04 07:54:22

标签: watir ole

我刚试过这个:$browser.execute_script("alert(\"aaa\")")

然后我收到以下错误:

h:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.2.0/lib/watir-classic/page-container.rb:46:in `method_missing': (in OLE method `execScript': ) (WIN32OLERuntimeError)
OLE error code:80020101 in <Unknown>
  Could not complete the operation due to error 80020101.HRESULT error code:0x80020009
  Exception occurred.
    from h:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.2.0/lib/watir-classic/page-container.rb:46:in `rescue in execute_script'
    from h:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.2.0/lib/watir-classic/page-container.rb:39:in `execute_script'

我错过了安装的东西吗?

2 个答案:

答案 0 :(得分:1)

该异常表示运行脚本时发生了javascript错误。

虽然修复脚本会更好,但是如果你真的想忽略这个异常,可以将它包装在begin-rescue中:

begin
    $browser.execute_script("asdfasd") 
rescue WIN32OLERuntimeError
    #Ignore javascript error that occurred
end

当异常发生时,救援人员将抓住它并允许程序继续。

答案 1 :(得分:0)

尝试单引号使其有效:

$browser.execute_script("alert('aaa')")