0
0
Selenium Pythontesting~5 mins

Opening URLs (get) in Selenium Python

Choose your learning style9 modes available
Introduction

Opening a URL in a browser lets you test how a website loads and behaves.

When you want to start testing a website from its homepage.
When you need to check if a specific webpage loads correctly.
When automating navigation to different pages during a test.
When verifying that links or redirects lead to the right page.
Syntax
Selenium Python
driver.get("https://example.com")

driver is your browser control object.

The URL must be a full web address starting with http:// or https://.

Examples
Open Google's homepage in the browser.
Selenium Python
driver.get("https://www.google.com")
Navigate directly to the About page of example.com.
Selenium Python
driver.get("https://example.com/about")
Sample Program

This script opens the URL https://example.com in a headless Chrome browser, prints the page title, then closes the browser.

Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import time

options = Options()
options.add_argument('--headless')  # Run browser without opening window
service = Service()
driver = webdriver.Chrome(service=service, options=options)

try:
    driver.get("https://example.com")
    print(f"Page title is: {driver.title}")
finally:
    driver.quit()
OutputSuccess
Important Notes

Always close the browser with driver.quit() to free resources.

Using headless mode lets tests run faster without opening a visible window.

If the URL is incorrect or the site is down, driver.get() may raise an error or timeout.

Summary

Use driver.get(url) to open a webpage in your test browser.

Make sure the URL is complete and correct.

Close the browser after testing to avoid resource leaks.