how_do_i_do_dis
how_do_i_do_dis

Reputation: 31

Opera WebDriver wont launch Opera (Selenium 3.1.0)

Its my first post, so I hope I will ask properly.

So as the title says, I have troubles launching Opera browser via Selenium WebDriver (I have tried versions 3.1.0 and 3.2.0). I use java to write code.

I have a code where you specify the browser that you want to use, and then a site you wanna go to. Chrome and Firefox works just fine, Opera is giving me quite a hell. Code:

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);

It fails on: Capabilities [{message=unknown error: Opera failed to start (Driver info: OperaDriver beta=0.1 (87cdb4f0d742fb950d1f0fca1f3f6b483e4fb69c),platform=Windows NT 10.0 x86_64), platform=ANY}] Session ID: d02baabe92d8bbfd90641a00d2458aef

Now I had some trouble making the driver find even find the Opera binaries... but managed by setting the path manually.

I am curious if anyone managed to get Opera working through WebDriver. On GitHub some guy claimed he managed to get it working, but with RemoteWebDriver while "hacking" the Opera to be run with ChromeDriver instead of OperaDriver. I have tried that as well and it did not work either (the process was that you find on which Chromium is your Opera based - my is Opera 43, that is based on Chromium 56, for which the chromium driver 2.27 is used - for more info about that process you can see: https://github.com/operasoftware/operachromiumdriver/issues/27 , but he did that on Mac, I dont know, if there might be some differences since I am on Windows machine.

There is no official support from the Opera itself, as far as I understood.

Is anyone running Selenium on Opera these days? If so, how did you manage to achieve that? Maybe I am missing something very basic...

Any tips or advice appreciated :)

Upvotes: 2

Views: 4486

Answers (3)

Daniel
Daniel

Reputation: 2998

Using Latest Selenium 3.13 and OperaDriver v2.37 You can do it using:

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 is the location of operadriver.exe (Nuget Package should install) BinaryLocation should point to the executable Opera Browser!

Upvotes: 0

megadevices
megadevices

Reputation: 191

I was able to run my tests in Opera 46, Windows 10 in the following way for webdriver 3.4.0 (local run):

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);

Upvotes: 1

Kaushal Rupani
Kaushal Rupani

Reputation: 186

Not sure if you are still looking for an answer but here is how I achieve opera execution using selenium 3.3 in ruby lang.

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

Eg:
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)

There is a very similar method to do the same in java as well, but the steps or logic remain the same.
1) Start ChromeService on some free port
2) Start chrome remote caps but pass binary of opera and --ignore-certificate-errors option
3) pass the url from service and caps to remote webdriver

Upvotes: 0

Related Questions