Unable to launch Opera using Python Selenium

旧时模样 提交于 2020-04-03 10:42:06

问题


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.


回答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/")
    



回答2:


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



来源:https://stackoverflow.com/questions/59815011/unable-to-launch-opera-using-python-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!