Testing already Open Browser with Watir-Webdriver

2019-04-01 23:35发布

问题:

This question already has an answer here:

  • Is there any way to attach an already running browser to selenium webdriver in java? [duplicate] 2 answers

I do not want to open a new browser by @browser = Watir::Browser.new (:ie) but i want to work with manually opened browser using Watir-Webdriver. How would I do that ?

I thought it may be something like this browser(:title => "Browser Title").text_field( :id => 'Field Id').set 'abc'

it seems like I need to create an Object of browser class to work it .. Please guide me?

回答1:

Selenium-webdriver does not have functionality for attaching to existing browsers. This feature was requested, but closed as not feasible (see Issue 18).

If you are only using IE, you could consider using Watir-Classic, which has functionality for attaching to existing browsers:

browser = Watir::Browser.attach(:title,  "Browser Title")
browser.text_field( :id => 'Field Id').set 'abc'

The main part of the API is the same between Watir-Webdriver and Watir-Classic. There are some small differences depending on what you are doing. Note that if your code is doing require 'watir', you might already be using Watir-Classic.