简体   繁体   中英

Chrome binary Error after new OS - Linux Mint installation

I have installed new Linux Mint in my computer. I have installed Github, pycharm. I downloaded the code. As per the packages requirement, i have installed the Selenium and other packages. The code below which was working in previous Ubuntu Linux Now it is downloading the code and its not working properly. It is throwing the error. For the first time, it is downloading the driver. Second time it is giving this error. Both times the code is not working. Please help me.

 code:-
    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.by import By
    from webdriver_manager.chrome import ChromeDriverManager
    s = Service(ChromeDriverManager().install())
    chrome_options = Options()
    chrome_options.add_experimental_option("detach",True)
    """
    The browser will be started.
    """
    browser = webdriver.Chrome(service=s, options=chrome_options)
    browser.maximize_window()
    browser.get("https://rahulshettyacademy.com")
    print(browser.title)
    browser.get("https://rahulshettyacademy.com/angularpractice/")
    print(browser.title)



 Error message:-
    /home/halovivek/PycharmProjects/yearcoding/venv/bin/python /home/halovivek/PycharmProjects/yearcoding/26092022_selenium1.py 
    Traceback (most recent call last):
      File "/home/halovivek/PycharmProjects/yearcoding/26092022_selenium1.py", line 13, in <module>
        browser = webdriver.Chrome(service=s, options=chrome_options)
      File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
        super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
      File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in __init__
        super().__init__(
      File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 270, in __init__
        self.start_session(capabilities, browser_profile)
      File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 363, in start_session
        response = self.execute(Command.NEW_SESSION, parameters)
      File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 428, in execute
        self.error_handler.check_response(response)
      File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
    Stacktrace:
    #0 0x55d1d6012693 <unknown>
    #1 0x55d1d5e0bb0a <unknown>
    #2 0x55d1d5e2e46e <unknown>
    #3 0x55d1d5e2c1f4 <unknown>
    #4 0x55d1d5e67953 <unknown>
    #5 0x55d1d5e61743 <unknown>
    #6 0x55d1d5e37533 <unknown>
    #7 0x55d1d5e38715 <unknown>
    #8 0x55d1d60627bd <unknown>
    #9 0x55d1d6065bf9 <unknown>
    #10 0x55d1d6047f2e <unknown>
    #11 0x55d1d60669b3 <unknown>
    #12 0x55d1d603be4f <unknown>
    #13 0x55d1d6085ea8 <unknown>
    #14 0x55d1d6086052 <unknown>
    #15 0x55d1d60a071f <unknown>
    #16 0x7f5a5a21a1da <unknown>
    #17 0x7f5a5a2a2d84 <unknown>
    
    
    Process finished with exit code 1

Similar to Selenium gives "unknown error: cannot find Chrome binary" when running chrome driver on Ubuntu , it means that either Chrome is not installed on your system, or it's not installed in the default location where it would be found on your PATH. If Chrome is installed, but in a special location, you can set it like this (after you put in a valid path):

from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = "/PATH/TO/YOUR/CHROME"
driver = webdriver.Chrome(chrome_options=options)

If Chrome isn't installed at all on your Linux machine, you can try existing solutions such as https://stackoverflow.com/a/62234251/7058266 or https://www.digitalocean.com/community/tutorials/install-chrome-on-linux-mint in order to install it into the default location on your PATH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM