import shutil from urllib.parse import quote 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.ui import Select html = """
""" options = Options() options.add_argument("--headless=new") options.add_argument("--window-size=1280,720") for browser_name in ("google-chrome", "chromium", "chromium-browser"): browser_path = shutil.which(browser_name) if browser_path: options.binary_location = browser_path break driver_path = shutil.which("chromedriver") service = Service(driver_path) if driver_path else None driver = webdriver.Chrome(service=service, options=options) try: driver.get("data:text/html;charset=utf-8," + quote(html)) menu = Select(driver.find_element(By.ID, "plan")) menu.select_by_visible_text("Team") selected = menu.first_selected_option selected_text = selected.text selected_value = selected.get_attribute("value") change_event_value = driver.find_element(By.ID, "result").text assert selected_text == "Team" assert selected_value == "team" assert change_event_value == "team" print(f"selected_text: {selected_text}") print(f"selected_value: {selected_value}") print(f"change_event_value: {change_event_value}") finally: driver.quit()