Methods of WebDriver and WebElement
1. WebDriver Methods:
Methods |
Description |
---|---|
get(String URL) |
Navigate the browser to the specified URL. |
findElement(By by) |
Locates a single WebElement based on the given locator strategy. |
findElements(By by) |
Locates multiple WebElements based on the given locator strategy. |
getTitle() |
Retrieves the title of the current web page. |
getCurrentUrl() |
Retrieves the URL of the current web page. |
close() |
Closes the current browser window. |
quit() |
Quits the WebDriver session, closing all browser windows associated with it. |
navigate() |
Provides methods to navigate the browser history (e.g., forward(), back()). |
2. WebElement Methods:
Methods |
Description |
---|---|
sendKeys(CharSequence… keysToSend) |
Enters text into an input field or sends keyboard keys to the element. |
click() |
Clicks the element. |
getText() |
Retrieves the visible text of the element. |
getAttribute(String name) |
Retrieves the value of the specified attribute of the element. |
isEnabled() |
Check if the element is enabled or not. |
isSelected() |
Check if the element is selected or not (applicable for checkboxes, radio buttons, etc.). |
isDisplayed() |
Check if the element is displayed on the web page. |
clear() |
Clears the text or input value of the element. |
Difference Between WebDriver and Web Element?
Although WebDriver helps with browser control and navigation, WebElements are the building blocks of automated test scripts that help find and interact with specific elements within web pages.
Table of Content
- What is WebDriver?
- What is WebElement?
- Methods of WebDriver and WebElement
- Difference between WebDriver and WebElement
- Conclusion
- FAQs
Understanding their functions and tasks is essential for efficient web automation testing and guaranteeing the resilience and dependability of online applications.