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. Use this to dismiss pop-up windows! This does not work on cookie consent banners." | |
inputs = {} | |
output_type = "string" | |
def __init__(self, driver: Any = None, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.driver = driver | |
self.is_initialized = False | |
def forward(self) -> str: | |
if not self.driver: | |
raise ValueError("WebDriver instance is required.") | |
ActionChains(self.driver).send_keys(Keys.ESCAPE).perform() | |
return "Pop-up closed." |