How to implement chromedriver in selenium in Linux platform
Asked Answered
E

6

22

Can somebody tell me how to use the Chrome driver in Selenium for Linux platform?

I have my chrome driver location at username/home/chromedriver.

My code is:

System.setProperty("webdriver.chrome.driver", "/home/username/ChromeDriver/chrome‌​driver");
driver = new ChromeDriver();
driver.get("facebook.com");

The error I am getting is:

org.openqa.selenium.WebDriverException: Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date.

Using Chrome binary at: /opt/google/chrome/google-chrome

(WARNING: The server did not provide any stacktrace information)

Earthenware answered 7/9, 2013 at 14:2 Comment(1)
The location of your Chrome driver (username/home/chromedriver) and your configuration (/home/username/ChromeDriver/chrome‌​driver) don't match. Make sure you use the right path at every location. Apart from this, everything should be ok, this is how I initialize mine Chrome, too. Try re-downloading all the parts once again. Don't forget to unzip the chromedriver package.Oakley
N
26

From [the official documentation](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver:

Requirements

The ChromeDriver controls the browser using Chrome's automation proxy framework.

The server expects you to have Chrome installed in the default location for each system:

OS          Expected Location of Chrome
-------------------------------------
Linux          /usr/bin/google-chrome
Mac            /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP     %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista  C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe

For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary. See also the section on overriding the Chrome binary location.

Getting Started

To get set up, first download the appropriate prebuilt server. Make sure the server can be located on your PATH or specify its location via the webdriver.chrome.driver system property. Finally, all you need to do is create a new ChromeDriver instance:

WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");

Therefore, download the version of chromedriver you need, unzip it somewhere on your PATH (or specify the path to it via a system property), then run the driver.

Nkvd answered 7/9, 2013 at 14:18 Comment(5)
Hi, I have my chrome driver location at "username/home/chromedriver" .So, i have my codeEarthenware
System.setProperty("webdriver.chrome.driver","/home/username/ChromeDriver/chromedriver");driver = new ChromeDriver(); driver.get("facebook.com"); The error am getting is , org.openqa.selenium.WebDriverException: Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date. Using Chrome binary at: /opt/google/chrome/google-chrome (WARNING: The server did not provide any stacktrace information)Earthenware
The documentation page that it links to contains no informationAdamantine
The download link doesn't work anymore in the "Getting Started" section.Breaking
@AaronLelevier Thank you, I fixed the links.Oakley
W
13

We have installed Successfully

sudo apt-get install unzip
wget -N http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip -P ~/Downloads
unzip ~/Downloads/chromedriver_linux64.zip -d ~/Downloads
chmod +x ~/Downloads/chromedriver
sudo mv -f ~/Downloads/chromedriver /usr/local/share/chromedriver
Change the directory to /usr/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

Now run the script and add the following in the environment file.

Capybara.register_driver :chrome do |app| client = Selenium::WebDriver::Remote::Http::Default.new Capybara::Selenium::Driver.new(app, :browser => :chrome, :http_client => client) end

Capybara.javascript_driver = :chrome

Note : Change the chrome driver version according to your operating system type like 32 bit or 64 bit.

Woolcott answered 26/2, 2015 at 4:45 Comment(2)
after doing "chmod -x ...", you can just do: "sudo mv -f ~/Downloads/chromedriver /usr/local/bin"Acrospire
These instructions are now quite old and the chrome driver version has changed many times. Make sure your Chrome browser version matches the driver version.Lotion
L
5

Here is a complete script for Linux 18.04 to install Google Chrome and the chrome driver. It should automatically adjust to collect the correct chrome driver for the browser.

#!/usr/bin/env bash
# install the latest version of Chrome and the Chrome Driver
apt-get update && apt-get install -y libnss3-dev
version=$(curl http://chromedriver.storage.googleapis.com/LATEST_RELEASE)
wget -N http://chromedriver.storage.googleapis.com/${version}/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d /usr/local/bin
chmod +x /usr/local/bin/chromedriver
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
Lotion answered 3/4, 2020 at 22:14 Comment(3)
while executing the last statement, it says Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root? even though I have given sudo privileges.Dira
I suspect it was because you already had dpkg or apt running somewhere else.Lotion
Nope. tt that is not the case. rechecked.. I get that error after this line Processing triggers for man-db (2.8.3-2ubuntu0.1) ... E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root? Dira
B
4

For me worked with these commands:

  1. Unziped the file -> unzip -q chromedriver_linux64.zip
  2. Force the copy to the directory 'usr/bin' -> sudo mv -f chromedriver /usr/bin

The selenium code was something like that.


System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");

WebDriver driver = new ChromeDriver();

driver.get("https://mvnrepository.com");

driver.close();
Biphenyl answered 14/4, 2018 at 16:14 Comment(1)
Thank you for this simple and to the point solution. I was able to resolve my "chromedriver needs to be in path..." error this way.Robers
R
0

You can see small example from this example

For linux, i downlaod chrome driver and keep as system path variable(or put in exist path folder). And from code i use following ways (add property and initiate with path of chrome driver)

System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
ChromeDriverService service = new ChromeDriverService.Builder()
                .usingDriverExecutable(new File("/usr/local/bin/chromedriver"))
                .usingAnyFreePort()
                .build();
        try {
            service.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
Romelda answered 27/6, 2016 at 23:58 Comment(0)
D
0

This shell script will assist you to download and install latest chrome driver and google chrome in your Linux.

#!/bin/sh
#get latest version
version=`curl http://chromedriver.storage.googleapis.com/LATEST_RELEASE)`;
echo 'Currently LATEST_RELEASE:' $version;
#download the latest version chrome driver available as per the above line
wget -N http://chromedriver.storage.googleapis.com/${version}/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d /usr/local/bin
chmod a+x /usr/local/bin/chromedriver
#install latest google chrome 
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
google_version=`google-chrome --version`;
echo 'Google Chrome Version:' $google_version;
echo 'End of the script'
Dudgeon answered 6/5, 2023 at 7:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.