The
WebDriver
interface is a fundamental component of Selenium and serves as the primary API for browser automation. It defines a set of methods and commands that allow you to interact with web browsers programmatically.
Here are some of the most commonly used methods of the
WebDriver
interface in Selenium:- get(String url):
- Loads a new web page in the current browser window/tab.
- Loads a new web page in the current browser window/tab.
- getCurrentUrl():
- Returns the URL of the currently loaded page.
- Returns the URL of the currently loaded page.
- getTitle():
- getPageSource():
- Returns the source code of the current page as a string.
- Returns the source code of the current page as a string.
- close():
- Closes the current browser window/tab.
- Closes the current browser window/tab.
- quit():
- Quits the WebDriver session, closing all browser windows/tabs associated with it.
- Quits the WebDriver session, closing all browser windows/tabs associated with it.
- getWindowHandle():
- Returns a unique identifier (handle) for the current window.
- Returns a unique identifier (handle) for the current window.
- getWindowHandles():
- Returns a set of unique identifiers (handles) for all open windows/tabs.
- Returns a set of unique identifiers (handles) for all open windows/tabs.
- switchTo():
- Provides methods for switching between browser windows, frames, or iframes.
- Provides methods for switching between browser windows, frames, or iframes.
- manage():
- Returns an instance of the
Options
interface, which allows you to manage browser-specific options and settings like timeouts, window management, and cookies.
- Returns an instance of the
- navigate():
- Provides methods for navigating to different web pages, refreshing the current page, and navigating backward or forward in the browser history.
- Provides methods for navigating to different web pages, refreshing the current page, and navigating backward or forward in the browser history.
- findElement(By by):
- Locates the first web element on the current page that matches the given locator strategy (e.g., by ID, name, CSS selector, XPath).
- Locates the first web element on the current page that matches the given locator strategy (e.g., by ID, name, CSS selector, XPath).
- findElements(By by):
- Locates all web elements on the current page that match the given locator strategy and returns them as a list.
- Locates all web elements on the current page that match the given locator strategy and returns them as a list.
- switchTo():
- Provides methods for switching between browser windows, frames, or iframes.
- Provides methods for switching between browser windows, frames, or iframes.
- manage().timeouts():
- Returns an instance of the
Timeouts
interface, which allows you to set timeout settings for waiting for elements or page loads.
- Returns an instance of the
0 Comments