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)

1

5 Answers

From [the official documentation](:

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 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(""); 

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.

5

We have installed Successfully

sudo apt-get install unzip wget -N -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.

2

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(""); driver.close(); 
1

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 ) wget -N unzip chromedriver_linux64.zip -d /usr/local/bin chmod +x /usr/local/bin/chromedriver wget dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install 
3

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()); 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy