Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a Chromium Browser with Selenium?

Is it possible to run a Selenium test in Chromium Browser (not Google Chrome Browser)?

My GoogleDrive location: GoogleDrive location

My Chromium location: Chromium location

FYI: I am using Java

My code ( for the moment I am run FirefoxDriver(gecko):

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MainClass {

public static void main (String[] args){
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\User\\IdeaProjects\\testselenium\\drivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get ("https://www.seleniumhq.org/");
   }
} 

I thought that this code would help but without success. Runs Google Chrome, not Chromium:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Chromium {

public static void main (String[] args){
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\IdeaProjects\\testselenium\\drivers\\chromedriver.exe");
    System.setProperty("webdriver.chrome.binary", "C:\\Users\\User\\Downloads\\chrome-win\\chrome-win\\chrome.exe");
    WebDriver driver = new ChromeDriver();
    driver.get ("https://www.seleniumhq.org/");
   }
} 

What could be the problem? How can this question be resolved?

like image 455
Nikita Milaserdov Avatar asked Feb 07 '19 07:02

Nikita Milaserdov


People also ask

Can you use Selenium with chromium?

Visit the link: https://chromedriver.chromium.org/downloads. There shall be links available for download for various chromedriver versions. Select the version which is compatible with the Chrome available to our system.

Can you use ChromeDriver with chromium?

Setup. ChromeDriver is a separate executable that Selenium WebDriver uses to control Chrome. It is maintained by the Chromium team with help from WebDriver contributors.

What is chromium Selenium?

Selenium and chromium are trace minerals that the body needs to support the growth, development and function of various physiological systems. Selenium aids the thyroid and is a necessary component of enzymes that trigger metabolism and cell regulation. Chromium is required for proper glucose absorption from the blood.


2 Answers

Chromium Browser have different version as follows:

  • Chrome Canary
  • Chrome from Dev Channel
  • Raw build of Chromium for Windows x64

Not sure which Chromium Browser version you are trying to use.

However to use Chrome Canary version you can use the ChromeOptions and setBinary() method to set the absolute path of the Chrome Canary binary and you can use the following solution:

  • Code Block:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    
    public class A_Chrome_Canary {
    
        public static void main(String[] args) {
    
            System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            ChromeOptions opt = new ChromeOptions();
            opt.setBinary("C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe");
            WebDriver driver = new ChromeDriver(opt);
            driver.get("https://www.google.com/");
            System.out.println(driver.getTitle());
        }
    }
    
  • Console Output:

    Google
    
  • Browser Snapshot:

Chrome_Canary


Update

Not clear from your comments but you need to download the latest Chromium binary from either of the official repositories:

  • The Chromium Projects
  • chromium.appspot
  • Chrome Canary - Nightly build for developers
like image 154
undetected Selenium Avatar answered Oct 03 '22 02:10

undetected Selenium


With the help of DebanjanB's answer, I developed the following code that can run on Chromium:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class A_Chrome_Canary {

    public static void main (String[] args){

    System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\IdeaProjects\\testselenium\\drivers\\chromedriver.exe");

    ChromeOptions opt = new ChromeOptions();

    opt.setBinary("C:\\Users\\User\\Downloads\\chrome-win\\chrome-win\\chrome.exe");

    WebDriver driver = new ChromeDriver(opt);

    driver.get("https://www.google.com/");

    System.out.println(driver.getTitle());

    }
}
like image 22
Nikita Milaserdov Avatar answered Oct 03 '22 04:10

Nikita Milaserdov