Spaces:
Running
Running
from typing import Any | |
from smolagents.tools import Tool | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver import ActionChains | |
class ClosePopupsTool(Tool): | |
name = "close_popups" | |
description = "Closes any visible modal or pop-up on the page by pressing ESCAPE. Does not work on cookie consent banners." | |
inputs = {} | |
output_type = "str" | |
def forward(self, driver: Any = None) -> str: | |
if not driver: | |
raise ValueError("WebDriver instance is required.") | |
ActionChains(driver).send_keys(Keys.ESCAPE).perform() | |
return "Pop-up closed." | |
def __init__(self, *args, **kwargs): | |
self.is_initialized = False |