Browser Commands Selenium With Python

In this article, we will discuss browser commands in selenium with python.

As you know selenium supports many languages. We can write selenium with Java, Javascript, Python, C#, Ruby, etc. All the methods will be same but there will be syntax differences between the languages that you use. Other than that the commands, names will be mostly similar to all languages. If you learned the concepts of selenium using anyone language strongly it is easier to learn and implement the test automation in all the languages as well.

Come let's see the commands one by one.


  • Create a project in pycharm IDE.
  • Selenium installed.( Else, you can — pip install selenium)

Install webdriver-manager by running the below command in command prompt.

pip install webdriver-manager

While setting the python interpreter, kindly refer the python.exe file path. This path will available in your appdata folder when you download python. All the libraries that you download using pip command will get installed inside the scripts folder. 

C:\User\<username>\Appdata\Local\programs\python\python<version> folder(for me python310)\Scripts

Eg of the file path: C:\User\<username>\Appdata\Local\programs\python\python<version> folder(for me python310)\python.exe


Browser commands selenium with python

If you do not want to refer local interperter setting like this way, then you can directly install the necessary libraries inside the project that you created and refer the scripts folder in the interpreter settings dialog box.


For Chrome browser, import the ChromeDriverManager and create the driver object as shown in the code snippet.

A Service class that is responsible for the starting and stopping of chromedriver.

We don't need to download the chromedriver.exe file and provide the path. when we run the test for the first time, the latest version of chromedriver gets downloaded and saved.

And it is used every time when we run test.

When your browser is updated the respective browser driver will automatically download and updated.

# importing the webdriver library
from selenium import webdriver
# importing service class
from import Service as ChromeService
# import the ChromeDriverManager
from import ChromeDriverManager

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))


The below command opens the browser with the desired webpage.

driver.get("<url of the application under test>")

The below command navigates backward. Equivalent to forward button in the browser.


The below command navigates backward. Equivalent to back button in the browser.


The below command refresh the browser.


The below command maximizes the window in the browser


The below command minimizes the window in the browser.


Cick command

The below command locates the webelement using the locator and click the element.

element = driver.find_element_by_id("test");

8 types of locators are supported which are mentioned below

  1. By CSS ID: driver.find_element_by_id
  2. By CSS class name: driver.find_element_by_class_name
  3. By name attribute: driver.find_element_by_name
  4. By DOM structure or Xpath: driver.find_element_by_xpath
  5. by tagName: driver.find_element_by_tag_name()
  6. By link text: driver.find_element_by_link_text
  7. By partial link text: driver.find_element_by_partial_link_text
  8. By HTML tag name: driver.find_element_by_tag_name

Fill command

The below command locates the webelement using the locator and enter input inside the input field.

element = driver.find_element_by_id("testing-id")
element.send_keys("test text")

The below command close the current browser instance.


The below command closes all the browser instances opened.


The below command gets the title of the page.

#print the title in the console

The below command gets the current URL of the page.

currenturl = driver.current_url;
#prints the currenturl in the console

Happy learning.

Similar Articles