Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

SeleniumScrapingTool only works the first time #379

@MaxPleaner

Description

@MaxPleaner

Here's a minimum reproducible example:

from crewai_tools import (
    SeleniumScrapingTool,
)

scrape_website_tool = SeleniumScrapingTool()

url = "https://halfrottengoddess.bandcamp.com/album/live-recordings"
tool = SeleniumScrapingTool(website_url=url, css_element=".track_list .track_title, .track_list .track_time, .track_list .title a")

result = tool._run()
print(result)

result = tool._run()
print(result)

The first time tool._run() is called, it prints the desired info:

COMPLEX '22 - Demeter
COMPLEX '22 - Breach
COMPLEX '22 - Black Hole City
XX ATTACK FEST '23 - Whistle Heart
XX ATTACK FEST '23 - Girl in Space
XX ATTACK FEST '23 - Cryochrist
POINT EMERY SOLAR VAN '22 - Thane

The second time, it raises this error:

Traceback (most recent call last):
  File "/Users/maxpleaner/Desktop/AI_Agent/art_crew/tests/selenium_test.py", line 11, in <module>
    result = tool._run()
             ^^^^^^^^^^^
  File "/Users/maxpleaner/Desktop/AI_Agent/art_crew/.venv/lib/python3.12/site-packages/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py", line 135, in _run
    self.driver.close()
  File "/Users/maxpleaner/Desktop/AI_Agent/art_crew/.venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 602, in close
    self.execute(Command.CLOSE)
  File "/Users/maxpleaner/Desktop/AI_Agent/art_crew/.venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 454, in execute
    self.error_handler.check_response(response)
  File "/Users/maxpleaner/Desktop/AI_Agent/art_crew/.venv/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#invalidsessionidexception
Stacktrace:
0   chromedriver                        0x0000000101364e6c cxxbridge1$str$ptr + 2722840
1   chromedriver                        0x000000010135cd74 cxxbridge1$str$ptr + 2689824
2   chromedriver                        0x0000000100eae260 cxxbridge1$string$len + 90252
3   chromedriver                        0x0000000100ee8cf8 cxxbridge1$string$len + 330532
4   chromedriver                        0x0000000100f112e4 cxxbridge1$string$len + 495888
5   chromedriver                        0x0000000100f105ec cxxbridge1$string$len + 492568
6   chromedriver                        0x0000000100e7d3d8 chromedriver + 87000
7   chromedriver                        0x0000000101327f88 cxxbridge1$str$ptr + 2473268
8   chromedriver                        0x000000010132b1f4 cxxbridge1$str$ptr + 2486176
9   chromedriver                        0x00000001013099d0 cxxbridge1$str$ptr + 2348924
10  chromedriver                        0x000000010132bab0 cxxbridge1$str$ptr + 2488412
11  chromedriver                        0x00000001012faa60 cxxbridge1$str$ptr + 2287628
12  chromedriver                        0x0000000100e7b664 chromedriver + 79460
13  dyld                                0x000000018d90ab98 start + 6076

This is a problem for usage within Agents, because frequently they need to use the scraper multiple times.

Reinitializing the tool works, though:

from crewai_tools import (
    SeleniumScrapingTool,
)

scrape_website_tool = SeleniumScrapingTool()

url = "https://halfrottengoddess.bandcamp.com/album/live-recordings"
tool = SeleniumScrapingTool(website_url=url, css_element=".track_list .track_title, .track_list .track_time, .track_list .title a")
result = tool._run()
print(result)

tool = SeleniumScrapingTool(website_url=url, css_element=".track_list .track_title, .track_list .track_time, .track_list .title a")
result = tool._run()
print(result)

So for usage with Agents, I think I need to make a custom wrapper Tool which re-initializes the Scraper each time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions