0

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

Modified the code as per advice .

import os
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.firefox import GeckoDriverManager
#options = Options()
options = webdriver.FirefoxOptions()
options.binary_location = r"/usr/bin/"
options.add_argument("start-maximized")
options.add_experimental_option("detach", True)
service = FirefoxService(log_path=os.devnull,)
browser = webdriver.Firefox(service= FirefoxService(GeckoDriverManager().install()), options=options)
#browser = webdriver.Firefox(service=service,options=options,)
capabilities = webdriver.FirefoxOptions().to_capabilities()
options.set_capability("cloud:options", capabilities)


browser.maximize_window()
browser.implicitly_wait(5)
browser.get("https://the-internet.herokuapp.com/windows")
print(browser.title)

Still error exist:-

/home/halovivek/PycharmProjects/yearcoding/venv/bin/python /home/halovivek/PycharmProjects/yearcoding/27092002_selenium3.py 
[WDM] - Downloading: 16.2kB [00:00, 11.9MB/s]                   
Traceback (most recent call last):
  File "/home/halovivek/PycharmProjects/yearcoding/27092002_selenium3.py", line 15, in <module>
    browser = webdriver.Firefox(service= FirefoxService(GeckoDriverManager().install()), options=options)
  File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/firefox/webdriver.py", line 177, 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.InvalidArgumentException: Message: binary is not a Firefox executable


Process finished with exit code 1
vivek rajagopalan
  • 843
  • 3
  • 13
  • 22

1 Answers1

0

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.


Here's an example of Firefox headless mode on Linux:

import os
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService

options = webdriver.FirefoxOptions()
options.add_argument("--headless")
capabilities = webdriver.FirefoxOptions().to_capabilities()
capabilities["moz:firefoxOptions"] = {"args": ["-headless"]}
options.set_capability("cloud:options", capabilities)

service = FirefoxService(
    log_path=os.devnull,
)
driver = webdriver.Firefox(
    service=service,
    options=options,
)

### Do things here ###

driver.quit()
Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
  • I tried the above code. still the error is coming. I installed chrome using flak pack which is used in Linux mint. Do i need to uninstall the google chrome and install again? – vivek rajagopalan Sep 26 '22 at 03:13
  • I would verify the location, and try setting it directly. It could be a permissions issue. If that file doesn't have the correct ``chmod`` permissions, then it might not be found even if it's really there. – Michael Mintz Sep 26 '22 at 03:41
  • I dont know how to set the location directly. – vivek rajagopalan Sep 26 '22 at 04:02
  • `options.binary_location = "/PATH/TO/YOUR/CHROME"` (you were already using options in your example) – Michael Mintz Sep 26 '22 at 04:07
  • My drivers are downloaded and kept in this location. /home/halovivek/Downloads/Education I tried and its not working – vivek rajagopalan Sep 26 '22 at 12:49
  • The binary is the Chrome browser binary, not the chromedriver. – Michael Mintz Sep 26 '22 at 13:01
  • i tried and found out two things. My firefox installed location is /usr/bin/firefox. if i enter this in terminal it is opening the firefox browser. for Google chrome this is the location. /home/halovivek/.var/app/com.google.Chrome/config/google-chrome if i type the above one i am getting this message - bash: /home/halovivek/.var/app/com.google.Chrome/config/google-chrome: Is a directory Please guide me to run in firefox at least. thank you – vivek rajagopalan Sep 27 '22 at 03:11
  • I added an example of running Firefox WebDriver in the solution. – Michael Mintz Sep 27 '22 at 03:39
  • hi i want to see the execution in firefox. Can you please change the headless to normal execution – vivek rajagopalan Sep 27 '22 at 06:07
  • Remove the `options.add_argument("--headless")` and `capabilities["moz:firefoxOptions"] = {"args": ["-headless"]}` lines for normal mode. – Michael Mintz Sep 27 '22 at 06:34
  • this is my code – vivek rajagopalan Sep 27 '22 at 12:48
  • Hi I am getting the new error again. Please check my code. selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable – vivek rajagopalan Sep 27 '22 at 12:51
  • Please check the post again. I have posted the modified code again. – vivek rajagopalan Sep 27 '22 at 12:57
  • It your latest edit, you mixed ``GeckoDriverManager`` with a ``Firefox()`` call, and then you set ``capabilities`` and ``options`` after you needed to use them in the ``Firefox()`` call. This led to the error you saw. – Michael Mintz Sep 27 '22 at 18:21
  • I am very much New person in programming. Can you please rewrite the code order to me? Please? Thanks a million. – vivek rajagopalan Sep 28 '22 at 03:17