问题
Is it possible to run a Selenium test in Chromium Browser (not Google Chrome Browser)?
My GoogleDrive location:

My 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?
回答1:
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:
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
回答2:
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());
}
}
来源:https://stackoverflow.com/questions/54567901/how-to-run-a-chromium-browser-with-selenium