0
0
Selenium Pythontesting~10 mins

Opening URLs (get) in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web browser and navigates to a specific URL. It verifies that the page title matches the expected title to confirm the correct page loaded.

Test Code - unittest
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import unittest

class TestOpenURL(unittest.TestCase):
    def setUp(self):
        service = Service()
        self.driver = webdriver.Chrome(service=service)
        self.driver.implicitly_wait(10)

    def test_open_url_and_check_title(self):
        url = "https://example.com"
        expected_title = "Example Domain"
        self.driver.get(url)
        actual_title = self.driver.title
        self.assertEqual(actual_title, expected_title, f"Page title should be '{expected_title}'")

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and WebDriver Chrome instance is createdChrome browser window opens, ready for commands-PASS
2Browser navigates to 'https://example.com' using driver.get()Browser loads the Example Domain page-PASS
3Retrieve the page title using driver.titlePage title is 'Example Domain'Check if actual title equals 'Example Domain'PASS
4Assert that the page title matches expected titleTitle matches expectedassertEqual passesPASS
5Test ends and browser is closed with driver.quit()Browser window closes-PASS
Failure Scenario
Failing Condition: The page title does not match the expected title after navigation
Execution Trace Quiz - 3 Questions
Test your understanding
What Selenium method is used to open a URL in the browser?
Adriver.get()
Bdriver.open()
Cdriver.navigate()
Ddriver.load()
Key Result
Always verify the page title after opening a URL to confirm the browser loaded the correct page before proceeding with further tests.