""" Example workflow integrating agent-permissions with Selenium. Prerequisites: pip install selenium agent-permissions # And ensure the appropriate WebDriver binary is on PATH. """ from __future__ import annotations from lxml import html from agent_permissions import discover_manifest, validate_interaction def validate_click(manifest_wrapper, selector: str) -> bool: """Helper to check whether a click is allowed.""" if manifest_wrapper is None or manifest_wrapper.manifest is None: return False dom = html.fromstring(manifest_wrapper.details.get("html", "")) matches = dom.cssselect(selector) if not matches: return False result = validate_interaction( manifest_wrapper.manifest, verb="click_element", element=matches[0], ) return result.allowed def main() -> None: try: from selenium import webdriver from selenium.webdriver.common.by import By except ImportError: # pragma: no cover - sample only raise SystemExit("Install selenium to run this example: pip install selenium") driver = webdriver.Chrome() driver.get("https://example.com/products") manifest_wrapper = discover_manifest( driver.current_url, html=driver.page_source, ) if manifest_wrapper is not None: manifest_wrapper.details.setdefault("html", driver.page_source) if validate_click(manifest_wrapper, "#buy"): driver.find_element(By.CSS_SELECTOR, "#buy").click() print("Clicked buy button in compliance with manifest.") else: print("Click denied by manifest or manifest missing.") driver.quit() if __name__ == "__main__": main()