Test Overview
This test opens a web page, finds an element using a CSS selector, clicks it, and verifies the expected text appears. It checks that the CSS selector correctly locates the element.
This test opens a web page, finds an element using a CSS selector, clicks it, and verifies the expected text appears. It checks that the CSS selector correctly locates the element.
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 TestCssSelectorSyntax(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/testpage') def test_click_button_with_css_selector(self): driver = self.driver # Wait until the button with CSS selector is present button = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, 'button.submit-btn.primary')) ) button.click() # Verify the success message appears success_msg = WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.alert-success')) ) self.assertEqual(success_msg.text, 'Submission successful!') 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/testpage' | Page loads with a button having class 'submit-btn primary' | - | PASS |
| 3 | WebDriverWait waits up to 10 seconds for button with CSS selector 'button.submit-btn.primary' to be present | Button element is found in the DOM | Element located by CSS selector exists | PASS |
| 4 | Clicks the button found by CSS selector | Button is clicked, triggering page update | - | PASS |
| 5 | WebDriverWait waits up to 10 seconds for 'div.alert-success' to be visible | Success message element appears with text 'Submission successful!' | Text of success message equals 'Submission successful!' | PASS |
| 6 | Test ends and browser closes | Browser window closes | - | PASS |