Using Cucumber 1.0.1 and Watir 1.9.2, I need to execute javascript code in order for a proprietary portal to do some navigation.
I am able to execute JS code with the following:
def execute_js(js_code)
@browser.goto("javascript:#{js_code};void(0)")
end
execute_js("doNavigate()")
By doing so, the navigation is done as expected but Watir doesn't re-take control of the browser.
I look for a solution for Watir to re-take control of the browser after the 'javascript goto'.
@browser.execute_script('alert("toto");')
gives me this:
execScript
OLE error code:80070005 in <Unknown>
Access Denied.
HRESULT error code:0x80020009
An exception occurred. (WIN32OLERuntimeError)
./features/lib/portal.rb:110:in `tln_main_tab'
I found a workaround:
def execute_js(js_code)
begin
Timeout::timeout(2) do
@browser.goto("javascript:#{js_code};void(0)")
end
rescue Exception => e
goto "#{@browser.url}#" # <<< workaround is here
return
end
end
execute_js("doNavigate()")
It's not ideal, but it enables javascript execution, then updates the URL hash so that Watir knows that an actual action was done, so that Watir can go further.
Access Denied
error message is usually connected to frames on a page. Take a look at Frames page at Watir wiki.
User contributions licensed under CC BY-SA 3.0