Selenium is an effective device for controlling an internet browser through the program. It is purposeful for all browsers, works on all fundamental OS and its scripts are written in numerous languages i.e Python, Java, C#, etc, we can be running with Python.
Requirement: You need to install chromedriver and set path. Click here to download.for more information follows this link.
WebDriver Navigational Commands:
- forward(): takes us to the next page as per the browser history
- back(): takes us to the previous page as per the browser history
Procedure:
- Importing the modules
- Creating an instance of Chrome.
- Go to the first URL i.e. www.neveropen,com
- Display the title of the page.
- Go to the second URL i.e. www.youtube,com
- Display the title of the page.
- Go to the previous page and display the title.
- Go to the next page and display the title.
Implementation:
Python3
# importing the modulesfrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport timeÂ
# using chrome driverdriver = webdriver.Chrome()Â
# taking first url# getting titleprint(driver.title)Â
# taking 2nd url# getting the titleprint(driver.title)Â
# given time open urltime.sleep(2)Â
# WebDriver Navigational Commands backwarddriver.back()# given time open urltime.sleep(2)# if back then given previous titleprint(driver.title)Â
# WebDriver Navigational Commands backwarddriver.forward()# given time open urltime.sleep(2)# if goto forward then given next titleprint(driver.title)Â
driver.close() |
Output:
