Assistance Needed: Differing Behavior in Selenium Scripts

Hello Replit Community,

I am reaching out for assistance regarding an intriguing issue I have encountered while working with Selenium WebDriver in Python. I have two scripts that utilize the Selenium WebDriver with Chrome, but they exhibit differing behaviors, and I’m trying to understand why.

The first script, which functions correctly, uses the following options for the Chrome WebDriver:

python

def get_chrome_options():
    chrome_options = Options()
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_argument('--headless')
    chrome_options.add_argument(f'user-agent={get_random_user_agent()}')
    return chrome_options

In contrast, the second script, which is a subordinate script called by a main script, fails with the following error messages:

bash

/nix/store/7q1b1bsmxi91zci6g8714rcljl620y7f-bash-5.2-p15/bin/sh: line 1: google-chrome: command not found
/nix/store/7q1b1bsmxi91zci6g8714rcljl620y7f-bash-5.2-p15/bin/sh: line 1: google-chrome-stable: command not found
/nix/store/7q1b1bsmxi91zci6g8714rcljl620y7f-bash-5.2-p15/bin/sh: line 1: google-chrome-beta: command not found
/nix/store/7q1b1bsmxi91zci6g8714rcljl620y7f-bash-5.2-p15/bin/sh: line 1: google-chrome-dev: command not found

This script has been configured with various Chrome options, with the most extensive being:

python

def get_chrome_options(headless=True):
    chrome_options = webdriver.ChromeOptions()
    if headless:
        chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3')
    chrome_options.add_argument('--ignore-ssl-errors=yes')
    chrome_options.add_argument('--ignore-certificate-errors')
    chrome_options.binary_location = "/nix/store/n6m949x5r35yf75yfaw504cb37n0fxcw-chromium-114.0.5735.106/bin/chromium-browser"
    return chrome_options

Despite these configurations, the script fails to execute as intended. The primary difference between the two scripts is that the non-working script is not just saving information but passing it further as part of a larger workflow managed by a main script.

I’ve tried various combinations of options but to no avail. I would deeply appreciate any insights or suggestions the community might have on resolving this issue. Has anyone else faced a similar situation, or does anyone have ideas on what might be causing this discrepancy?

Thank you for your time and assistance.

Best regards