Nikita Milaserdov
Nikita Milaserdov

Reputation: 141

How to run a Chromium Browser with Selenium?

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

My Google Drive location:

Google Drive location

My Chromium location:

Chromium location

FYI: I am using Java

My code (at the moment I am running 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 it was without success. It 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?

Upvotes: 6

Views: 24813

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193298

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:

Upvotes: 9

Nikita Milaserdov
Nikita Milaserdov

Reputation: 141

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

    }
}

Upvotes: 3

Related Questions