web-arena-x / webarena

Code repo for "WebArena: A Realistic Web Environment for Building Autonomous Agents"
https://webarena.dev
Apache License 2.0
647 stars 94 forks source link

how to get observation space of real website #87

Closed njucckevin closed 5 months ago

njucckevin commented 6 months ago

Hi! The WebArena has a very clean and simplified observation space of the accessibility tree. I would like to know for real websites, are there scripts for converting web pages to structured text like this? thanks for your help~

shuyanzhou commented 6 months ago

@oootttyyy can you share the script you used?

oootttyyy commented 6 months ago

Hi @njucckevin You can convert web pages to their accessibility tree forms with this script:

with sync_playwright() as p:
    browser = p.chromium.launch()  
    page = browser.new_page()
    page.goto("file:///path/to/your/example.html") 
    cdp_client = page.context.new_cdp_session(page)
    obs_handler = ObservationHandler(
    "text",
    "accessibility_tree",
    "",
    False,
    {"width": 1280, "height": 1080},
    )
    cdp_client.send(
    "Accessibility.enable", {}
    )
    obs = obs_handler.get_observation(page, cdp_client)
    obs_metadata = obs_handler.get_observation_metadata()

Where obs would be the accessibility tree