What are the types of WebDriver methods?
Overview: In this blog, you can read about what are the types of webDriver methods and their usage in automation testing.
Topics:
What are the types of Webdriver methods
List of classes implementing WebDriver.
Web Element Commands.
Selenium Webdriver Methods:
Selenium webdriver has many abstract methods "String url", "quit()", "close()", "getWindowHandle()", "getTitle()", "getWindowHandles(), etc.. it has nested interface like window navigation, timeouts, etc.. these elements are used to perform operations like forward(), back(), etc..
- get(String URL): It will launch a new browser with the given URL in the browser instance.
- getwindowHandle(): It is used to handle single-window ie. main window. it will return the browser window handle from the focused browser and its return type is a string.
- getWindowHandles(): It is used to handle multiple windows. it will return all handles from all the opened browsers by webdriver and its return type is Set.
- close(): It will close the current browser window which is currently in focus.
- quite(): It will close all the web browser windows which are currently opened and stop the webdriver session.
- getTitle(): This method will return the currently opened webpage title.
List of classes implementing WebDriver:
The Classes of the webDriver interface are Edge Driver, FirefoxDriver, ChromeDriver, InternetExplorerDriver e.t.c Each driver class is similar to a browser. It will help you to execute the selenium script on different browsers. The user can create the object of the driver classes and work with them.
Web Element Commands:
The selenium web element representing Html elements. Refer to the commonly used web elements commands.
- findElement(): This method is used to find the first element in the current web page by using given locators. Example: driver.find_element_by_"Enter locator type"("value")
- sendKeys(): This method is used to send any text message to the given input field (Edit, Text box) in the current web page. Example: driver.find_element_by_"Enter locator type"("value").send_keys("Enter text you want to send")
- clear(): it will clear the value from an input field (Edit, Text box) Example: driver.find_element_by_"Enter locator type"("value").clear()
- click(): it clicks a clickable element (Link, Button, Checkbox) Example: driver.find_element_by_"Enter locator type"("value").click()
Selenium with Web Driver print Website title Command:
Source code:
from selenium import webdriver # import selenium webdriver library
import string
driver = webdriver.Firefox(
executable_path="/Users/yudiz/Automation/flowerShop/bin/geckodriver")
# firefox driver class file
driver.get("https://harshit873.github.io/") # open webpage in the new page
title = driver.title # get the title of a current opened webpage.
print("The title of a webpage is -> " + title) # print webpage name in the console.
Output:
Comments
Post a Comment