Spaces:
Running
Running
Update tools/close_popups.py
Browse files- tools/close_popups.py +21 -19
tools/close_popups.py
CHANGED
@@ -1,19 +1,21 @@
|
|
1 |
-
from typing import Any
|
2 |
-
from smolagents.tools import Tool
|
3 |
-
from selenium.webdriver.common.keys import Keys
|
4 |
-
from selenium.webdriver import ActionChains
|
5 |
-
|
6 |
-
class ClosePopupsTool(Tool):
|
7 |
-
name = "close_popups"
|
8 |
-
description = "Closes any visible modal or pop-up on the page
|
9 |
-
inputs = {}
|
10 |
-
output_type = "
|
11 |
-
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
1 |
+
from typing import Any
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
from selenium.webdriver.common.keys import Keys
|
4 |
+
from selenium.webdriver import ActionChains
|
5 |
+
|
6 |
+
class ClosePopupsTool(Tool):
|
7 |
+
name = "close_popups"
|
8 |
+
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."
|
9 |
+
inputs = {}
|
10 |
+
output_type = "string"
|
11 |
+
|
12 |
+
def __init__(self, driver: Any = None, *args, **kwargs):
|
13 |
+
super().__init__(*args, **kwargs)
|
14 |
+
self.driver = driver
|
15 |
+
self.is_initialized = False
|
16 |
+
|
17 |
+
def forward(self) -> str:
|
18 |
+
if not self.driver:
|
19 |
+
raise ValueError("WebDriver instance is required.")
|
20 |
+
ActionChains(self.driver).send_keys(Keys.ESCAPE).perform()
|
21 |
+
return "Pop-up closed."
|