Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SeleniumURLLoader to use webdriver Service in favor of deprecated executable_path parameter #9814

Merged
merged 1 commit into from Aug 30, 2023

Conversation

aaravindan101
Copy link
Contributor

Description: This commit uses the new Service object in Selenium webdriver as executable_path has been deprecated and removed in selenium version 4.11.2
Issue: #9808
Tag Maintainer: @eyurtsev

Note -
First attempt was to create a Service object and pass empty if executable_path not provided as such:
`def _get_driver(self) -> Union["Chrome", "Firefox"]:
"""Create and return a WebDriver instance based on the specified browser.

Raises:
    ValueError: If an invalid browser is specified.

Returns:
    Union[Chrome, Firefox]: A WebDriver instance for the specified browser.
"""
if self.browser.lower() == "chrome":
    from selenium.webdriver import Chrome
    from selenium.webdriver.chrome.options import Options as ChromeOptions
    from selenium.webdriver.chrome.service import Service

    chrome_options = ChromeOptions()
    chrome_service = Service()

    for arg in self.arguments:
        chrome_options.add_argument(arg)

    if self.headless:
        chrome_options.add_argument("--headless")
        chrome_options.add_argument("--no-sandbox")
    if self.binary_location is not None:
        chrome_options.binary_location = self.binary_location
    if self.executable_path is None:
        chrome_service.path = self.executable_path
    return Chrome(options=chrome_options, service=chrome_service)
elif self.browser.lower() == "firefox":
    from selenium.webdriver import Firefox
    from selenium.webdriver.firefox.options import Options as FirefoxOptions
    from selenium.webdriver.firefox.service import Service

    firefox_options = FirefoxOptions()
    firefox_service = Service()

    for arg in self.arguments:
        firefox_options.add_argument(arg)

    if self.headless:
        firefox_options.add_argument("--headless")
    if self.binary_location is not None:
        firefox_options.binary_location = self.binary_location
    if self.executable_path is None:
        firefox_service.path = self.executable_path
    return Firefox(options=firefox_options, service=firefox_service)
else:
    raise ValueError("Invalid browser specified. Use 'chrome' or 'firefox'.")`

However in testing I found this crashes when executable_path is not passed in with the follow Exception: NoSuchDriverException(f"Unable to locate or obtain driver for {options.capabilities['browserName']}"). This updated pull request revises to only pass Service object when executable_path is provided

@vercel
Copy link

vercel bot commented Aug 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Aug 27, 2023 1:11am

@dosubot dosubot bot added Ɑ: doc loader Related to document loader module (not documentation) 🤖:improvement Medium size change to existing code to handle new use-cases labels Aug 27, 2023
@baskaryan
Copy link
Collaborator

thanks for the fix @aaravindan101!!

@baskaryan baskaryan merged commit 6a51672 into langchain-ai:master Aug 30, 2023
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: doc loader Related to document loader module (not documentation) 🤖:improvement Medium size change to existing code to handle new use-cases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants