Search code examples
rubygoogle-chromebrowserwatir

Closing then opening browser with Watir


I want to close the current browser, open a new one and let it continue it's work. It looks something like this:

browser = Watir::Browser.new :chrome
.....
browser = browser.close


browser = browser.new
..

But after closing the browser it returns

uninitialized constant Browser (NameError)

Thanks :)


Solution

  • when you call browser.close, the browser object gets removed after the actual browser is closed. To make a new one you need to use the same syntax you did the first time (as indicated by Justin in the comments to your question)

    browser = Watir::Browser.new :chrome