Force the browser to end the current step

3

Need:

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.

Issue:

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.

What I look for:

I look for a solution for Watir to re-take control of the browser after the 'javascript goto'.

Tested alternative:

@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'

Local gems:

  • Ascii85 (0.9.0)
  • builder (3.0.0)
  • bundler (1.0.15)
  • capybara (1.0.0)
  • childprocess (0.1.9)
  • commonwatir (1.9.2)
  • cucumber (1.0.1)
  • diff-lcs (1.1.2)
  • ffi (1.0.9 x86-mingw32)
  • firewatir (1.9.2)
  • fuubar-cucumber (0.0.12)
  • gherkin (2.4.5 x86-mingw32)
  • hoe (2.10.0)
  • json (1.5.3)
  • json_pure (1.5.3)
  • mime-types (1.16)
  • nokogiri (1.5.0 x86-mingw32)
  • pdf-reader (0.9.0)
  • prawn (0.11.1)
  • rack (1.3.0)
  • rack-test (0.6.0)
  • rake (0.9.2)
  • rautomation (0.6.2)
  • rspec (2.6.0)
  • rspec-core (2.6.4)
  • rspec-expectations (2.6.0)
  • rspec-mocks (2.6.0)
  • ruby-progressbar (0.0.10)
  • rubygems-update (1.8.5)
  • rubyzip (0.9.4)
  • s4t-utils (1.0.4)
  • selenium-webdriver (0.2.2)
  • syntax (1.0.0)
  • term-ansicolor (1.0.5)
  • ttfunk (1.0.1)
  • user-choices (1.1.6.1)
  • viewcumber (0.1.2)
  • watir (1.9.2)
  • win32-api (1.4.8 x86-mingw32)
  • win32-process (0.6.5)
  • win32console (1.3.0 x86-mingw32) -windows-api (0.4.0)
  • windows-pr (1.2.0)
  • xml-simple (1.1.0)
  • xpath (0.1.4)
javascript
cucumber
watir
asked on Stack Overflow Jul 18, 2011 by Arnaud Leymet • edited Jul 20, 2011 by Lightness Races in Orbit

2 Answers

1

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.

answered on Stack Overflow Jul 20, 2011 by Arnaud Leymet
0

Access Denied error message is usually connected to frames on a page. Take a look at Frames page at Watir wiki.

answered on Stack Overflow Jul 19, 2011 by Ċ½eljko Filipin

User contributions licensed under CC BY-SA 3.0