File size: 700 Bytes
9cb4e3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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