问题
I just tried this:$browser.execute_script("alert(\"aaa\")")
and then I get the error below:
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'
Am I missing install something?
回答1:
The exception means that a javascript error occurred when running the script.
While it would be better to fix the script, but if you really want to ignore the exception, you could wrap it in a begin-rescue:
begin
$browser.execute_script("asdfasd")
rescue WIN32OLERuntimeError
#Ignore javascript error that occurred
end
When the exception occurs, the rescue will catch it and allow the program to continue.
回答2:
Try if single quotes make it work:
$browser.execute_script("alert('aaa')")
来源:https://stackoverflow.com/questions/13698335/ole-error-code-80020101-caused-by-execute-script-of-waitr