0

My code works perfectly on the local device and I tried deploying to the replit server where I'm greeted with that error chromedriver unexpectedly exited. Status code was: 127

I tried placing a static file of chromedriver and all, still getting the same error. Here's my code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import os

class ScreenshotTaker:
    def __init__(self):
        # Set up Chrome options for headless browsing
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')

        # Create a new Chrome browser instance
        self.driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)

    def take_screenshot(self, html_file_path, output_file_path):
        # Get the full path to the HTML file
        html_file = os.path.abspath(html_file_path)

        # Load the local HTML file
        self.driver.get('file://' + html_file)

        # Take a screenshot of the page
        output_file = os.path.abspath(output_file_path)
        self.driver.save_screenshot(output_file)
        print("Screenshot saved successfully.")

    def close_browser(self):
        # Close the browser
        self.driver.quit()
  • Might have been terminated by the VM for violating a quota, such as memory limits. Though I would expect that from Chrome rather than chromedriver. – Ouroborus May 28 '23 at 07:34

1 Answers1

0

just try removing the ChromeDriverManager().install() i dont know why but whenever I do I it works

Heres the updated code

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import os

class ScreenshotTaker:
    def __init__(self):
        # Set up Chrome options for headless browsing
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')

        # Create a new Chrome browser instance
        self.driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)

    def take_screenshot(self, html_file_path, output_file_path):
        # Get the full path to the HTML file
        html_file = os.path.abspath(html_file_path)

        # Load the local HTML file
        self.driver.get('file://' + html_file)

        # Take a screenshot of the page
        output_file = os.path.abspath(output_file_path)
        self.driver.save_screenshot(output_file)
        print("Screenshot saved successfully.")

    def close_browser(self):
        # Close the browser
        self.driver.quit()
    ```
edwinsanjo
  • 11
  • 2