Search code examples
rubywatir

watir switch between drivers


I created multiple browsers and I'm in need to switch between them however when I go the conventional way I get this error message.which is like this

browser[i].button(:name=>'submit').click

the error that pops up:-

Browsing context has been discarded (Selenium::WebDriver::Error::NoSuchWindowError)

which made me think that I need to switch between browser[0] and browser[1] however switch to is not defined for a browser. any ideas?

browser[i].switch_to.window(browser[(i+1)%z].window_handle)

Solution

  • You are trying to connect with two different browser which has been opened by two different driver, you can shift between browser which has been opened by one single driver. For an example when you click a link if it opens a new window then you can shift to the new window.

    You can shift to the new window by writing the following code

     b.windows.last.use do |browser|
           browser.button.click #for an example
     end