1

我刚试过这个:$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'

我错过了安装的东西吗?

4

2 回答 2

1

异常意味着运行脚本时发生了 javascript 错误。

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

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

当异常发生时,救援会捕获它并允许程序继续运行。

于 2012-12-05T14:18:39.420 回答
0

试试单引号是否可以工作:

$browser.execute_script("alert('aaa')")
于 2012-12-06T14:43:46.710 回答