26

In the Selenium options (on Firefox) I can find Custom browser.

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

Robert Siemer
  • 32,405
  • 11
  • 84
  • 94
RusAlex
  • 8,245
  • 6
  • 36
  • 44

8 Answers8

32

Uh, the accepted answer doesn't answer the question. Google Chrome is based on Chromium, but they're not the same browser.

This is what you want: (since Chromium isn't officially supported)

DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*custom C:/path/to/chromium.exe" , "www.google.com");
selenium.start();

Edit 2018-08: Looks like the accepted answer changed to a copy of this one several years later, so my original comment is no longer correct. I'm leaving it there, but struck out, because the votes are misleading if I straight remove it.

Izkata
  • 8,961
  • 2
  • 40
  • 50
9

On Unix systems, you can do something like

sudo ln -s /usr/lib/chromium-browser/chromium-browser /usr/bin/google-chrome

And then you can use "*googlechrome" as the launch parameter when creating your DefaultSelenium instance.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mryan
  • 318
  • 3
  • 5
5

(Python)

You can use chromium-chromedriver instead of the vanilla chromedriver. It can be installed via apt-get like "sudo apt-get install chromium-chromedriver"

In my scripts I then configure the chromebrowser and driver to use the chromium exe and chromedriver exe like:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.BinaryLocation = "/usr/bin/chromium-browser"

driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver",options=options)
driver.get("https://www.google.com")
Dylan
  • 49
  • 1
  • 3
4

Yes. For Chromium, use:

DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*custom path/to/chromium", "www.google.com");
selenium.start();

The other options that you can use are *custom, *chrome (note: this is not Google Chrome; it’s a Firefox mode only), *googlechrome, *iexplore. Please check the Selenium documentation for complete list of the modes.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
9ikhan
  • 1,177
  • 3
  • 11
  • 22
2

It's probably too easy, and I'm going to figure out what I did that is horribly wrong, but...

    ChromeOptions options = new ChromeOptions();

    options.BinaryLocation = "C:\Program Files (x86)\Chromium\Application\chrome.exe");

    using (var chrome = new ChromeDriver(options))

appears to work...

Steve
  • 976
  • 12
  • 12
0

Yes, it is...

In a Linux you can install, to use without an X Window (example: in a webserver) too... It’s nice to some tests.

apt install chromium-shell

In code, you'll need a chromedriver. Look at this:

chromedriver

In this case I'll use Python code, to open a Chromium instance in a headless mode:

def startBot():
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')
    driver = webdriver.Chrome('/opt/chromedriver85', options=chrome_options)
    #driver.set_window_size(1366, 728)
    #aguardar carregamento em segundos
    driver.implicitly_wait(5)

    print("Get URL...")
    driver.get("https://www.google.com")

Obs.:

A headless browser is a great tool for automated testing and server environments where you don't need a visible UI shell. (source)

That's it!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Deividson Calixto
  • 350
  • 1
  • 4
  • 11
0

For me, just add:

chrome_options.binary_location = "/usr/bin/chromium-browser"

Sample code:

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=1, size=(1600, 902))
display.start()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--profile-directory=Default")
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-plugins-discovery")
chrome_options.add_argument("--start-maximized")
chrome_options.binary_location = "/usr/bin/chromium-browser"
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.delete_all_cookies()
driver.set_window_size(800, 800)
driver.set_window_position(0, 0)
print("arguments done")
driver.get("http://google.com")

It works with Version 104.0.5112.101 (Official Build) Built on Ubuntu, running on Ubuntu 18.04 (64-bit).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tiana987642
  • 696
  • 2
  • 10
  • 28
0

On Ubuntu, I managed to run Chromium by launching it from Selenium like a standard Chrome without any modifications by installing the chromium-chromedriver package.

TL;DR:

If you happen to run Ubuntu, which switched to that questionable Chromium snap, a fitting chromedriver is already included. The executable is on the the PATH already: /snap/bin/chromium.chromedriver.

And if you also happen to use a vanilla selenium which searches for chromedriver in the PATH, the supposedly transitional do-nothing-package chromium-chromedriver (dpkg) is actually providing that: an “executable” (shell-script) /usr/bin/chromedriver exec-ing the above mentioned snap version.

On this Ubuntu 20.04 (Focal Fossa) installation, I also happened to have this transitional chromium-browser package, which is probably not needed at all, but it also provides a (useless?) wrapper and made me try a matching chromium-chromedriver package version first. I have both on 1:85.0.4183.83-0ubuntu0.20.04.2 from focal-updates.

python3 -m venv venv
. venv/bin/activate
pip install selenium
python3

In the REPL:

from selenium import webdriver
d = webdriver.Chrome()
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Robert Siemer
  • 32,405
  • 11
  • 84
  • 94