Test Overview
This test opens a web page and finds a button using a CSS selector. It then clicks the button and verifies the button's text changes as expected.
This test opens a web page and finds a button using a CSS selector. It then clicks the button and verifies the button's text changes as expected.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import unittest class TestFindElementByCssSelector(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/button') def test_click_button_by_css_selector(self): driver = self.driver # Wait until button is present button = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, 'button.submit-btn')) ) button.click() # Verify button text changed updated_text = WebDriverWait(driver, 10).until( EC.text_to_be_present_in_element((By.CSS_SELECTOR, 'button.submit-btn'), 'Clicked') ) self.assertTrue(updated_text) def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open and ready | - | PASS |
| 2 | Browser navigates to 'https://example.com/button' | Page with a button having class 'submit-btn' is loaded | - | PASS |
| 3 | Waits up to 10 seconds for button with CSS selector 'button.submit-btn' to be present | Button element is found on the page | Element located by CSS selector 'button.submit-btn' exists | PASS |
| 4 | Clicks the button found by CSS selector | Button is clicked, triggering text change | - | PASS |
| 5 | Waits up to 10 seconds for button text to change to include 'Clicked' | Button text updated to 'Clicked' or contains 'Clicked' | Button text contains 'Clicked' | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |