Spaces:
Running
Running
Update tools/scroll_page.py
Browse files- tools/scroll_page.py +8 -0
tools/scroll_page.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
from smolagents.tools import Tool
|
2 |
from helium import scroll_down, scroll_up, get_driver
|
3 |
from selenium.webdriver.common.by import By
|
|
|
|
|
|
|
4 |
|
5 |
class ScrollPageTool(Tool):
|
6 |
name = "scroll_page"
|
@@ -13,9 +16,14 @@ class ScrollPageTool(Tool):
|
|
13 |
output_type = "string"
|
14 |
|
15 |
def __init__(self, driver):
|
|
|
16 |
self.driver = driver
|
|
|
|
|
17 |
|
18 |
def forward(self, selector=None, num_pixels=1200, direction="down"):
|
|
|
|
|
19 |
try:
|
20 |
if selector:
|
21 |
element = self.driver.find_element(By.CSS_SELECTOR, selector)
|
|
|
1 |
from smolagents.tools import Tool
|
2 |
from helium import scroll_down, scroll_up, get_driver
|
3 |
from selenium.webdriver.common.by import By
|
4 |
+
import logging
|
5 |
+
|
6 |
+
logger = logging.getLogger(__name__)
|
7 |
|
8 |
class ScrollPageTool(Tool):
|
9 |
name = "scroll_page"
|
|
|
16 |
output_type = "string"
|
17 |
|
18 |
def __init__(self, driver):
|
19 |
+
super().__init__()
|
20 |
self.driver = driver
|
21 |
+
self.is_initialized = self.driver is not None
|
22 |
+
logger.debug(f"ScrollPageTool initialized: is_initialized={self.is_initialized}")
|
23 |
|
24 |
def forward(self, selector=None, num_pixels=1200, direction="down"):
|
25 |
+
if not self.is_initialized:
|
26 |
+
return "Error: ScrollPageTool is not initialized"
|
27 |
try:
|
28 |
if selector:
|
29 |
element = self.driver.find_element(By.CSS_SELECTOR, selector)
|