Selenium WebDriver Commands
We will discuss the various commands provided by WebDriver some of the basic selenium commands for performing operations like
opening a URL, get the title of the webpage and closing browser etc.
Below are the most commonly used selenium commands provided by the
webdriver for Browser and Navigation.
1) Get() method:
get() method is used to loading
web Page on to the current browser. It accepts String as a parameter
Ex: driver.get(“https://google.com”)
2) Title() method
title() method fetches the title of the current web page.it
returns the string value.
Ex: driver.title
3) Current_url() method
Current_url() method fetches
the current url of the opened browser. It returns the string value.
Ex: driver.current_url
4) Page_source() method
Page_source method fetches the
source code of the opened browser. It returns the string value.
Ex: driver.page_source()
5) Maximize_window() method
Maximize_window() method is used to maximized your currently opened
browser.
Ex:
driver.maximize_window()
6) Minimize_window() method
Minimize_window() method is used to minimized your currently
opened browser.
Ex: driver.minimize_window()
7) Refresh() method
Refresh() method is used to
refresh your currently opened browser.
Ex: driver.refresh()
8) Forward() method
Forward() method is used to
navigating to forward in browser
history.
Ex: driver.forward()
9) back() method
back() method is used to
navigating to backward in browser
history.
Ex: driver.back()
10) close() method
Close() method is used to close
currently active browser.
Ex: driver.close()
11) quit() method
Quit() method is used to close all opened browser which are
associated to driver. This command basically shuts down the driver instance and any
further commands to WebDriver results in exception.
Ex: driver.quit()
Below is the script for above command/methods
from selenium.webdriver.common.by import By
chromePath="C:\\BrowserDrivers\\chromedriver.exe"
driver=webdriver.Chrome(executable_path=chromePath)
driver.get("http://newtours.demoaut.com")
# maiximize the window
driver.minimize_window()
# get the title of the web page
title=driver.title
print("title of the Page is ",title)
# get the current url
currenturl= driver.current_url
print("Current url of the web page is ",currenturl)
# get the source code of the page
pagesoruce=driver.page_source
print("soruces code of the current page is ")
print("-----------------------------------------------------------------------------")
print(pagesoruce)
print("-----------------------------------------------------------------------------")
# refresh the page
driver.refresh()
# nagivate to backward
driver.back()
# close the current window
driver.close()
Comments
Post a Comment