File size: 788 Bytes
634f689
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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."