Search currently open browser windows (firefox) with Watir

I am trying to write a script that will search and use a browser window (it could be IE or Firefox) that is already open before the script runs. The attach method works for IE, but it cannot work with Firefox.

browser = Watir::Browser.attach(:url, /url.com/) 

Using Watir-Webdriver I tried a window switch trick located elsewhere, but this only works when clicking a link from the original browser window. It seems he cannot find a window that was already open before the script was run.

The user community on blogs in other places tells me that this is only possible with IE and using watir and not watir-webdriver. There is a problem open in selenium for the tracker for webdriver, but it has been open for quite some time.

I hope to find a workaround there. Any ideas?

+4
source share
2 answers

Webdriver does not support binding to existing processes, so none of them can use watir-webdriver

+2
source

I found this while looking for a solution to the same problem.

Something I came across was writing a very simple Ruby web service using Sinatra and letting it treat the browser object as a global variable:

 require 'rubygems' require 'sinatra' require 'watir-webdriver' set :port, 9000 get '/openbrowser' do $browser = Watir::Browser.new :ff $timeout_length = 30 $browser.driver.manage.window.maximize end get '/closebrowser' do $browser.close end 

Then add a second script request to send HTTP requests to the web service as follows:

 require 'net/http' require 'uri' url = "http://localhost:9000/openbrowser" uri = URI.parse(url) Net::HTTP.get(uri) sleep(5) url = "http://localhost:9000/closebrowser" uri = URI.parse(url) Net::HTTP.get(uri) 

That way, you can open the browser and use it with independent scripts if you want, and close it when you're done.

The bad news: you will probably need a lot of rework if you already have something.

The good news is: if you start from scratch, you can build it quickly. And, if you store your browser objects in an array, you can test against multiple browsers in parallel if you do such things.

Hope this helps (although he is 3 years late)

0
source

Source: https://habr.com/ru/post/1499470/


All Articles