Thanks to visit codestin.com
Credit goes to www.geeksforgeeks.org

Open In App

Navigating links using get method in Selenium – Python

Last Updated : 09 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Selenium’s Python module allows you to automate web testing using Python. The Selenium Python bindings provide a straightforward API to write functional and acceptance tests with Selenium WebDriver. Through this API, you can easily access all WebDriver features in a user-friendly way. This article explains how to use Selenium with Python to navigate to a web page using the get() method of Selenium WebDriver. If you have not installed Selenium and its components yet, install them from here Selenium Python Introduction and Installation

What is the get() method ?

get() method in Selenium WebDriver is used to load a web page by navigating to the provided URL. When you call this method, WebDriver will send a GET request to the server and load the page. The WebDriver will wait for the page to fully load before giving control back to your script.

Syntax:

driver.get(“url”)

Step-by-Step Implementation

1. Install Selenium (if not already installed):

pip install selenium

2. Create a Python script named run.py:

from selenium import webdriver


# Initialize WebDriver (e.g., Firefox or Chrome)

driver = webdriver.Firefox()


# Open Google

driver.get(“https://www.google.com”)


# Close browser

driver.quit()

Example:

Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time

# Launch browser and open Google
drv = webdriver.Chrome()
drv.get("https://www.google.com")

# Search "GeeksforGeeks"
box = drv.find_element(By.NAME, "q")
box.send_keys("GeeksforGeeks", Keys.RETURN)

# Wait and close browser
time.sleep(5)
drv.quit()

Output

Navigating links using get method

Explanation: This code opens a browser and goes to a website. It finds the search input field and types in a query. Then, it submits the query to perform a search. After waiting a few seconds for the results to load, it closes the browser.


Next Article
Practice Tags :

Similar Reads