Table of Contents

Interface IWebDriver

Namespace
OpenQA.Selenium
Assembly
WebDriver.dll

Defines the interface through which the user controls the browser.

public interface IWebDriver : ISearchContext, IDisposable
Inherited Members
Extension Methods

Remarks

The IWebDriver interface is the main interface to use for testing, which represents an idealized web browser. The methods in this class fall into three categories:

  • Control of the browser itself
  • Selection of IWebElements
  • Debugging aids

Key properties and methods are Url, which is used to load a new web page by setting the property, and the various methods similar to FindElement(By), which is used to find IWebElements.

You use the interface by instantiate drivers that implement of this interface. You should write your tests against this interface so that you may "swap in" a more fully featured browser when there is a requirement for one.

Properties

CurrentWindowHandle

Gets the current window handle, which is an opaque handle to this window that uniquely identifies it within this driver instance.

string CurrentWindowHandle { get; }

Property Value

string

PageSource

Gets the source of the page last loaded by the browser.

string PageSource { get; }

Property Value

string

Remarks

If the page has been modified after loading (for example, by JavaScript) there is no guarantee that the returned text is that of the modified page. Please consult the documentation of the particular driver being used to determine whether the returned text reflects the current state of the page or the text last sent by the web server. The page source returned is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the response sent from the web server.

Title

Gets the title of the current browser window.

string Title { get; }

Property Value

string

Url

Gets or sets the URL the browser is currently displaying.

string Url { get; set; }

Property Value

string

Remarks

Setting the Url property will load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete. This will follow redirects issued either by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over, since should the underlying page change while your test is executing the results of future calls against this interface will be against the freshly loaded page.

See Also

WindowHandles

Gets the window handles of open browser windows.

ReadOnlyCollection<string> WindowHandles { get; }

Property Value

ReadOnlyCollection<string>

Methods

Close()

Close the current window, quitting the browser if it is the last window currently open.

void Close()

Manage()

Instructs the driver to change its settings.

IOptions Manage()

Returns

IOptions

An IOptions object allowing the user to change the settings of the driver.

Navigate()

Instructs the driver to navigate the browser to another location.

INavigation Navigate()

Returns

INavigation

An INavigation object allowing the user to access the browser's history and to navigate to a given URL.

Quit()

Quits this driver, closing every associated window.

void Quit()

SwitchTo()

Instructs the driver to send future commands to a different frame or window.

ITargetLocator SwitchTo()

Returns

ITargetLocator

An ITargetLocator object which can be used to select a frame or window.