Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement chromedriver in selenium in Linux platform

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)

like image 720
user2732362 Avatar asked Sep 07 '13 14:09

user2732362


People also ask

How do I start ChromeDriver on Linux?

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.

Does ChromeDriver work with Linux?

In order for Chromedriver to work on Linux, you'll have to install Chrome binary. For Chromedriver version, it'll be dependent on your Chrome binary version.

How do I integrate a Chrome driver using Selenium?

Go to the terminal and type the command: sudo nano /etc/paths. Enter the password. At the bottom of the file, add the path of your ChromeDriver. Type Y to save.


2 Answers

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.

like image 106
Petr Janeček Avatar answered Oct 20 '22 00:10

Petr Janeček


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.

like image 21
Kalyan Kumar Avatar answered Oct 20 '22 00:10

Kalyan Kumar