如何使用OperaChromiumDriver来支持Opera版本 >12.X

4
我了解到,为了在Opera版本大于12.X上工作,开发了Operachromiumdriver。但同时我无法让它正常工作。我从https://github.com/operasoftware/operachromiumdriver/releases下载了Windows版本的operachromiumdriver.exe,但是没有成功。请问有人能帮助我吗?请告诉我我的理解是否正确。
谢谢。

1
请添加一些您尝试过的代码,展示您如何使用operachromiumdriver.exe。 - StrikerVillain
3个回答

5
我发现了一种解决方法,可以在运行Opera 25+时使用OperaChromiumDriver.exe。
  1. Install Opera 25+ (I installed Opera 25)
  2. Download OperaChromiumDriver https://github.com/operasoftware/operachromiumdriver/releases
  3. Extract the zip file to a location on the computer
  4. Use the following code to open Opera

    System.setProperty("webdriver.chrome.driver", "C:/Users/user/Downloads/operadriver-0.1.0-win32/operadriver-0.1.0-win32.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.google.com");
    driver.findElement(By.name("q")).sendKeys("Selenium");
    
我已经使用了new ChromeDriver()。由于我们使用的是OperaChromiumDriver,因此这将启动Opera浏览器。我认为这是因为新版Opera基于Chromium,而OperaChromiumDriver是从ChromeDriver派生的WebDriver实现。[请参见https://github.com/operasoftware/operachromiumdriver]。希望这可以帮助你。

谢谢。我会尝试这个并回复您。 - dev

2
OperaChromiumDriver现在可以与Opera 26+一起使用,但目前仅限于远程实例...请从OperaChromiumDriver二进制发布下载并启动适当的二进制文件。
它们在Python中为桌面版提供了示例,但以下是我在Java中使用的内容。许多ChromeOptions不起作用,尽管它们应该...您将不得不测试以确保,但setBinary确实有效。
DesiredCapabilities capabilities = DesiredCapabilities.opera();

ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/opera");

capabilities.setCapability(ChromeOptions.CAPABILITY, options);

driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"),capabilities);

可以使用ChromeDriver作为OperaDriver v 0.2.2的替代,因为它只支持Opera 32版本。请参见评论https://github.com/operasoftware/operachromiumdriver/issues/17。 - Lukus

2

Operachromiumdriver

下载selenium 驱动程序。由于没有直接的Opera驱动程序,因此OperaChromiumDriver基于ChromeDriver,因此我们使用ChromeOptions来设置operadriver.exe的二进制位置。

基于Chromium的Opera版本从26开始。

String operaChromiumDriver = "E:\\Drivers\\operadriver.exe";
String operaBrowserLocation = "C:\\......\\opera.exe"

System.setProperty("webdriver.opera.driver", operaChromiumDriver);

ChromeOptions options = new ChromeOptions();
options.setBinary(operaBrowserLocation);        

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
OperaDriver browser = new OperaDriver(capabilities);

WebDriver driver =browser;
driver.get("https://in.yahoo.com/");

感谢Lukus Answer(1)帮我完成了工作。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接