Firoj112 commited on
Commit
634f689
·
verified ·
1 Parent(s): 08a5992

Update tools/close_popups.py

Browse files
Files changed (1) hide show
  1. 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 by pressing ESCAPE. Does not work on cookie consent banners."
9
- inputs = {}
10
- output_type = "str"
11
-
12
- def forward(self, driver: Any = None) -> str:
13
- if not driver:
14
- raise ValueError("WebDriver instance is required.")
15
- ActionChains(driver).send_keys(Keys.ESCAPE).perform()
16
- return "Pop-up closed."
17
-
18
- def __init__(self, *args, **kwargs):
19
- self.is_initialized = False
 
 
 
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."