首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Opera WebDriver不会启动Opera (Selenium 3.1.0)

Opera WebDriver不会启动Opera (Selenium 3.1.0)
EN

Stack Overflow用户
提问于 2017-03-09 21:33:16
回答 3查看 4K关注 0票数 2

这是我的第一篇文章,所以我希望我会问得更好。

因此,正如标题所说,我在通过Selenium WebDriver启动Opera浏览器时遇到了麻烦(我已经尝试了3.1.0和3.2.0版本)。我用java写代码。

我有一个代码,你可以在其中指定你想要使用的浏览器,然后是你想要访问的网站。Chrome和Firefox运行得很好,Opera让我下了地狱。代码:

代码语言:javascript
复制
public class Browser {

    public WebDriver driver;

    public void startWebDriver (String browser) {
        if (browser == "Chrome") {
            driver = new ChromeDriver();
        }

        else if (browser == "Firefox") {
            System.setProperty("webdriver.gecko.driver", "c:\\Users\\...\\webdriver\\geckodriver.exe");
            driver = new FirefoxDriver();
        }

        else if (browser == "Opera") {
            ChromeOptions options = new ChromeOptions();
            options.addArguments("user-data-dir = c:\\Users\\...\\AppData\\Roaming\\Opera Software\\Opera Stable");
            options.setBinary("c:\\Program Files\\Opera\\43.0.2442.1144");
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            System.setProperty("webdriver.opera.driver", "c:\\Users\\...\\operadriver.exe");
            driver = new OperaDriver(capabilities);

启动失败: Capabilities {message=unknown错误: Opera无法启动(驱动程序信息: OperaDriver beta=0.1 (87cdb4f0d742fb950d1f0fca1f3f6b483e4fb69c),platform=Windows NT 10.0 x86_64),platform=ANY}会话ID: d02baabe92d8bbfd90641a00d2458aef

现在我在让司机找到Opera二进制文件时遇到了一些麻烦。而是通过手动设置路径来管理。

我很好奇有没有人能通过WebDriver让Opera运行起来。在GitHub上,一些人声称他设法让它工作,但在“黑客”使用ChromeDriver而不是OperaDriver的时候使用了RemoteWebDriver。我也尝试过,但也不起作用(过程是,你发现哪个铬是你的Opera为基础的-我的是Opera43,这是基于铬56,其中铬驱动程序2.27被用于-)有关这个过程的更多信息,你可以看到:https://github.com/operasoftware/operachromiumdriver/issues/27,但他在Mac上做了,我不知道是否会有一些差异,因为我是在Windows机器上。

据我所知,没有来自Opera本身的官方支持。

最近有人在Opera上运行Selenium吗?如果是这样的话,你是怎么做到的?也许我遗漏了一些非常基本的东西。

如有任何建议或建议,欢迎使用:)

EN

回答 3

Stack Overflow用户

发布于 2017-07-13 14:49:11

我能够在Opera 46,Windows 10中以webdriver 3.4.0 (本地运行)的方式运行我的测试:

代码语言:javascript
复制
System.setProperty("webdriver.chrome.driver", "operadriver.exe");
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Program Files\\Opera\\46.0.2597.39\\opera.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
票数 1
EN

Stack Overflow用户

发布于 2017-04-18 13:22:52

不确定您是否还在寻找答案,但下面是我如何在ruby lang中使用selenium 3.3实现opera执行的方法。

语法

service = Selenium::WebDriver::Chrome::Service.new("<path to operadriver>", <any free port>, {optional so leave it blank}) service.start

例如:

service = Selenium::WebDriver::Chrome::Service.new("/usr/local/bin/operadriver", 12345, {}) service.start cap = Selenium::WebDriver::Remote::Capabilities.chrome('operaOptions' => {'binary' => '/Applications/Opera.app/Contents/MacOS/Opera', 'args' => ["--ignore-certificate-errors"]}) driver = Selenium::WebDriver.for(:remote, :url => service.uri, :desired_capabilities => cap)

在java中也有一个非常类似的方法来做同样的事情,但步骤或逻辑保持不变。

1)在一些空闲端口上启动ChromeService

2)启动chrome remote caps,但传递opera和--ignore-certificate-errors选项的二进制文件

3)将来自service和caps的url传递给远程webdriver

票数 0
EN

Stack Overflow用户

发布于 2018-07-19 05:45:29

使用最新的Selenium 3.13和OperaDriver v2.37,您可以使用:

代码语言:javascript
复制
string LibraryDir = new FileInfo((new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath).DirectoryName.Replace("%20", " ");
OperaOptions ooptions = new OperaOptions();
ooptions.BinaryLocation = @"C:\Program Files\Opera\54.0.2952.54\opera.exe";
_Browser = new OperaDriver(LibraryDir, ooptions);

LibraryDir是operadriver.exe (Nuget包应该安装)的位置,BinaryLocation应该指向可执行的Opera浏览器!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42696777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档