0

I am trying to launch opera using python selenium libraries. But getting capabilities error.

Codes I have tried:

Code1:

driver = webdriver.Opera()
driver.get('https://www.google.com')

Code2:

driver = webdriver.Opera(r'path to operadriver.exe')
driver.get('https://www.google.com')

Code3:

options = Options()
options.binary_location = r'C:\Opera\launcher.exe'
driver = webdriver.Opera(options=options)
driver.get('https://www.google.com')

Output:

Code1:

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary

Code2:

selenium.common.exceptions.WebDriverException: Message: Desired Capabilities must be a dictionary

Code3:

[20904:3220:0120/034255.122:ERROR:os_crypt_win.cc(61)] Failed to decrypt: The parameter is incorrect. (0x57)

DevTools listening on ws://127.0.0.1:59016/devtools/browser/0bb7bc3c-4b9a-451a-a736-a02a63feba7a
[20904:3220:0120/034255.673:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)
[20904:3220:0120/034255.674:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)
[20904:3220:0120/034255.675:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)

Only with code 3 the Opera browser launchers. But URL doesn't opens.

As I am able to launch chrome with similar codes.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
ROCHIT SHARMA
  • 53
  • 2
  • 4
  • Remember to mark the answer that solves your issue. See: https://stackoverflow.com/help/someone-answers – Jortega Jan 20 '20 at 01:32

2 Answers2

1

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary

and this error message...

selenium.common.exceptions.WebDriverException: Message: Desired Capabilities must be a dictionary

and this error message...

[20904:3220:0120/034255.122:ERROR:os_crypt_win.cc(61)] Failed to decrypt: The parameter is incorrect. (0x57)

...implies that the OperaDriver was unable to initiate/spawn a new Browsing Context i.e. Opera Browser session.


Solution

First of all you need to ensure that, you have downloaded the latest OperaChromiumDriver from operasoftware / operachromiumdriver. As per OperaDriver for Chromium-based Opera releases:

OperaChromiumDriver is a WebDriver implementation derived from ChromeDriver and adapted by Opera that enables programmatic automation of Chromium-based Opera products for desktop and Android platforms. It is a part of the Selenium project.

OperaChromiumDriver can be used without extra setup on Chromium-based versions of Opera starting from version 26.

Use both the arguments:

  • binary_location for opera binary and
  • executable_path for operadriver binary
  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.opera.options import Options
    
    options = Options()
    options.binary_location = r'C:\Opera\launcher.exe'
    driver = webdriver.Opera(options=options, executable_path=r'C:\path\to\operadriver.exe')
    driver.get("http://google.com/")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Still it's failing. Opera is launching but URL doesn't open. Below are the errors: ` selenium.common.exceptions.WebDriverException: Message: unknown error: Opera failed to start: exited normally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location C:\Users\AppData\Local\Programs\Opera\launcher.exe is no longer running, so OperaDriver is assuming that Opera has crashed.) (Driver info: OperaDriver=79.0.3945.79 (29f75ce3f42b007bd80361b0dfcfee3a13ff90b8-refs/branch-heads/3945@{#916}),platform=Windows NT 10.0.18362 x86_64) ` – ROCHIT SHARMA Jan 20 '20 at 16:10
  • @ROCHITSHARMA Hmm, it's still failing but with error `DevToolsActivePort file doesn't exist`. But your **initial errors** `cannot find Opera binary`, `Desired Capabilities must be a dictionary` and `Failed to decrypt: The parameter is incorrect` are resolved now. Can you raise a new question as per your new requirement please? – undetected Selenium Jan 20 '20 at 16:14
  • but my issue was that Opera is not launching URL. for same I used 3 different codes. The one you mentioned was in code3. And it is still giving same errors. Opera opens but URL doesn't. – ROCHIT SHARMA Jan 20 '20 at 16:17
  • Issue still persists – ROCHIT SHARMA Jan 28 '20 at 08:05
0

This worked for me:

from selenium import webdriver
from selenium.webdriver.opera.options import Options

options = Options()
driver = webdriver.Opera(options=options)
driver.get("https://www.google.com")

I also get the same errors you showed but the URLs I need to open are being loaded automatically in Opera without issue.

You need to make sure your opera version matches the version of the driver. check it by opening opera and enter this: opera://about Ensure the operadriver.exe is on the same folder of the python script.

The driver can be downloaded here: https://github.com/operasoftware/operachromiumdriver/releases

Heberth
  • 3
  • 3
  • Can @Heberth clue us how in, to verify what version of opera per version of the driver matches? FAIL (session not created: This version of OperaDriver only supports Opera version 85 (Driver info: operadriver=85.0.4183.102 (ffe848af6a5df4fa127e2929331116b7f9f1cb30-refs/branch-heads/4183@{#1770}),platform=Windows NT 10.0.18363 x86_64) (WARNING: The server did not provide any stacktrace information) This error message should surely tell me that driver version 85 is for opera 71, the message looks wrong. –  Sep 17 '20 at 09:40
  • My other struggle is that I cannot find the about box in Opera. –  Sep 17 '20 at 09:53