Test Overview
This test uses a custom expected condition to wait until a button's text changes to "Ready" before clicking it. It verifies that the button is clickable only after the text update.
This test uses a custom expected condition to wait until a button's text changes to "Ready" before clicking it. It verifies that the button is clickable only after the text update.
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 class button_text_to_be: def __init__(self, locator, text): self.locator = locator self.text = text def __call__(self, driver): element = driver.find_element(*self.locator) if element.text == self.text: return element else: return False def test_button_text_change_and_click(): driver = webdriver.Chrome() driver.get("https://example.com/buttonpage") wait = WebDriverWait(driver, 10) button_locator = (By.ID, "start-button") # Wait until button text changes to 'Ready' button = wait.until(button_text_to_be(button_locator, "Ready")) button.click() # Verify some result after click result_element = driver.find_element(By.ID, "result") assert result_element.text == "Success" driver.quit()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open, ready to navigate | - | PASS |
| 2 | Navigates to https://example.com/buttonpage | Page with a button having ID 'start-button' is loaded | - | PASS |
| 3 | Waits until button text changes to 'Ready' using custom expected condition | Button initially shows 'Start', then changes to 'Ready' within 10 seconds | Checks if button text equals 'Ready' | PASS |
| 4 | Clicks the button after text is 'Ready' | Button is clickable and clicked | - | PASS |
| 5 | Finds element with ID 'result' to verify outcome | Result element is present on page | Asserts that result element text is 'Success' | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |