如何使用Selenium运行Chromium浏览器? [英] How to run a Chromium Browser with Selenium?

查看:321
本文介绍了如何使用Selenium运行Chromium浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Chromium浏览器(不是Google Chrome浏览器)中运行Selenium测试?

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

我的GoogleDrive位置:

My GoogleDrive location:

我的Chromium位置:

My Chromium location:

仅供参考:我正在使用Java

FYI: I am using Java

我的代码(目前我正在运行FirefoxDriver(gecko):

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/");
   }
} 

我认为这段代码会ld帮助但没有成功。运行Google Chrome,而不是Chromium:

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/");
   }
} 

可能是什么问题?

推荐答案

Chromium Browser 具有以下不同的版本:

Chromium Browser have different version as follows:


  • Chrome Canary

  • 来自 Dev Channel的Chrome

  • 用于Windows x64的 Chromium的原始版本

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

不确定您要使用哪个 Chromium Browser 版本。

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

但是要使用 Chrome Canary 版本,您可以使用 ChromeOptions setBinary()方法来设置 Chrome Canary 二进制文件的绝对路径您可以使用以下解决方案:

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:

    您的评论不清楚,但您需要从两个官方存储库中下载最新的 Chromium 二进制文件:

    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

    这篇关于如何使用Selenium运行Chromium浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆