'WebDriverException: no chrome binary at /usr/bin/google-chrome-stable or chrome binary not found

I am executing selenium test via Jenkins server in AWS Ubuntu.

I was getting chrome binary not found error so I set chrome binary in my code.

System.setProperty("webdriver.chrome.driver","/var/lib/jenkins/.m2/repository/webdriver/chromedriver/linux64/83.0.4103.39/chromedriver");    
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("applicationCacheEnabled", true);
ChromeOptions options = new ChromeOptions();
options.merge(capabilities);
options.setBinary("/usr/bin/google-chrome-stable");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--remote-debugging-port=9222");
options.addArguments("--disable-infobars"); 
options.addArguments("--disable-dev-shm-usage"); //Linux 
options.addArguments("--disable-browser-side-navigation"); 
options.addArguments("--disable-gpu"); //Windows
options.addArguments("--disable-web-security");
driver = new ChromeDriver(options);

Then the error changed to: no chrome binary at /usr/bin/google-chrome-stable

Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 14665
Only local connections are allowed.
ChromeDriver was started successfully.
 INFO [main] (ControlCenter.java:108)- START
[ERROR] Tests run: 4, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 2.116 s <<< FAILURE! - in TestSuite
[ERROR] com.info.end2end.ExcelAccountToFusion.onTestSetup  Time elapsed: 2.032 s  <<< FAILURE!
org.openqa.selenium.WebDriverException: 
**unknown error: no chrome binary at /usr/bin/google-chrome-stable**
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'jenkins-it02', ip: '10.113.0.187', os.name: 'Linux', os.arch: 'amd64', os.version: '5.3.0-1019-aws', java.version: '11.0.7'
Driver info: driver.version: ChromeDriver

This is how my usr/bin is: binary folders

And this is message when I try to launch browser in command line: launch chrome

I tried the solution given by @DebanjanB at Cannot find Chrome binary with Selenium in Python for older versions of Google Chrome but no luck. Any help is much appreciated as I have spent 2 days on this already.



Solution 1:[1]

Not sure if setBinary() should be pointing to /usr/bin/google-chrome-stable.

As per the documentation in How To Install Google Chrome 78 On a RHEL/CentOS 7 and Fedora Linux to install and use the latest using Yum you need to follow the sequence below:

  1. Open the Terminal application. Grab 64bit Google Chrome installer.
  2. Type the following command to download 64 bit version of Google Chrome:

    wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
    
  3. Install Google Chrome and its dependencies on a CentOS/RHEL, type:

    sudo yum install ./google-chrome-stable_current_*.rpm
    
  4. Start Google Chrome from the CLI:

    google-chrome &
    

Outputs from yum command:

yum-google-chrome-command

Finally, you need to use the following line to set the chrome binary:

options.setBinary("/usr/bin/google-chrome");

Additional Considerations

Ensure that:

  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Reference

You can find a couple of relevant discussions in:

Solution 2:[2]

I did not have the actual fix for this issue but I could get around my actual blocker by installing Chromium instead of Chrome. Difference I found is the installation directory of both.

I installed Chrome and whereis Google-Chrome-Stable gives:

qa_user@jenkins:~$ whereis google-chrome-stable google-chrome-stable: /usr/bin/google-chrome-stable /usr/share/man/man1/google-chrome-stable.1.gz

And qa_user@jenkins:~$ google-chrome-stable gives: google-chrome-stable: command not found

Now for Chromium:

qa_user@jenkins:~$ whereis chromium-browser gives: chromium-browser: /usr/bin/chromium-browser /usr/lib/chromium-browser /etc/chromium-browser /usr/share/chromium-browser /usr/share/man/man1/chromium-browser.1.gz

and qa_user@jenkins~$ chromium-browser [21304:21304:0607/135202.629230:ERROR:browser_main_loop.cc(1473)] Unable to open X display. Identifies and opens Chromium (X display issue can be solved by adding --headless option in actual Selenium code).

So I am gonna use Chromium instead of Chrome until I/Someone here find the fix for the actual Chrome issue here.

Solution 3:[3]

UPDATE: After my below solution, I uninstalled Chromium and kept only Chrome for further testing. Surprisingly, chrome issue got fixed. I am able to run tests in Chrome now. Not sure how this is happening but I think it has something to do with dependency package that comes with Chrome.

I know this is strange but installing Chrome and Chromium and then uninstalling Chromium worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 undetected Selenium
Solution 2 Afsal
Solution 3 Afsal