Browser Interaction in Selenium WebDriver

Posted By :Rohitesh Rawat |29th June 2018

Browser Interaction and Navigating Web Pages:

Some attributes are methods and others are properties. All the method attributes ends with round brackets.

Some of the commands along with their description are explained below:

1- maximize_window(): Maximizes the current window that webdriver is using. It is a method.

2- driver.get(url): Loads a web page in the current browser session. It is a method.

3- driver.title: Returns the title of the current page. It is a property.

4- driver.current_url: URL of the current loaded page. It is a property.

5- driver.get(driver.current_url): Refreshes the current page. It is a method.

6- driver.refresh(): Refreshes the current page. It is a method.

7- driver.page_source: Gets the source of the current page. It is a property.

8- driver.back(): Goes one step backward in the browser history. It is a method.

9- driver.forward(): Goes one step forward in the browser history. It is a method.

10- driver.close(): Closes the current window. It is a method.

11- driver.quit(): Quits the driver and close every associated window. It is a method.

 

Example:

from selenium import webdriver

class BrowserInteractions():

    def test(self):
        baseUrl = "https://letskodeit.teachable.com/pages/practice"
        driver = webdriver.Firefox()

        # Window Maximize
        driver.maximize_window()
        # Open the Url
        driver.get(baseUrl)
        # Get Title
        title = driver.title
        print("Title of the web page is: " + title)
        # Get Current Url
        currentUrl = driver.current_url
        print("Current Url of the web page is: " + currentUrl)
        # Browser Refresh
        driver.refresh()
        print("Browser Refreshed 1st time")
        driver.get(driver.current_url)
        print("Browser Refreshed 2nd time")
        # Open another Url
        driver.get("https://sso.teachable.com/secure/42299/users/sign_in?reset_purchase_session=1")
        currentUrl = driver.current_url
        print("Current Url of the web page is: " + currentUrl)
        # Browser Back
        driver.back()
        print("Go one step back in browser history")
        currentUrl = driver.current_url
        print("Current Url of the web page is: " + currentUrl)
        # Browser Forward
        driver.forward()
        print("Go one step forward in browser history")
        currentUrl = driver.current_url
        print("Current Url of the web page is: " + currentUrl)
        # Get Page Source
        pageSource = driver.page_source
        print(pageSource)
        # Browser Close / Quit
        # driver.close()
        driver.quit()

ff = BrowserInteractions()
ff.test()

About Author

Rohitesh Rawat

Rohitesh is an expert in Agile methodologies, specializing in Scrum. He possesses a wide range of skills, including proficiency in Jira, MongoDB, planning, scoping, process creation and management, and QA. Over the years, he has led the successful delivery of several offshore projects, including Konfer, Virgin Media, HP1T, and Transleqo. Rohitesh holds certifications as a Certified Scrum Master (CSM) and Project Management Professional (PMP) and has a comprehensive understanding of the entire Project Life Cycle (PLC).

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us