from pathlib import Path import shutil from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait page_url = (Path(__file__).parent / "explicit-wait-demo.html").resolve().as_uri() options = Options() options.add_argument("--headless=new") options.add_argument("--window-size=1280,720") browser_path = shutil.which("google-chrome") or shutil.which("chromium") if browser_path: options.binary_location = browser_path driver_path = shutil.which("chromedriver") service = Service(driver_path) if driver_path else Service() driver = webdriver.Chrome(service=service, options=options) try: driver.get(page_url) wait = WebDriverWait(driver, 5) wait.until( EC.text_to_be_present_in_element((By.ID, "status"), "Ready to submit"), "order status did not become ready", ) button = wait.until( EC.element_to_be_clickable((By.ID, "submit-order")), "submit button did not become clickable", ) ready_status = driver.find_element(By.ID, "status").text button_text = button.text button.click() wait.until( EC.text_to_be_present_in_element((By.ID, "status"), "Submitted"), "order status did not change to Submitted", ) result_status = driver.find_element(By.ID, "status").text print(f"ready: {ready_status}") print(f"button: {button_text}") print(f"result: {result_status}") finally: driver.quit()