operasoftware / operachromiumdriver

OperaDriver for Chromium-based Opera releases
Other
261 stars 47 forks source link

"Could not find Opera binary" error in Python #31

Open einsteinsfool opened 7 years ago

einsteinsfool commented 7 years ago

I wrote this code using Python bindings:

from selenium import webdriver

browser = webdriver.Opera()
browser.get('http://seleniumhq.org/')
browser.quit()

...and got the following error:

Traceback (most recent call last):
  File "tests/OperaTest.py", line 9, in <module>
    browser = webdriver.Opera()
  File "/usr/lib/python3.4/site-packages/selenium/webdriver/opera/webdriver.py", line 73, in __init__
    service_log_path=service_log_path)
  File "/usr/lib/python3.4/site-packages/selenium/webdriver/opera/webdriver.py", line 52, in __init__
    service_log_path=service_log_path)
  File "/usr/lib/python3.4/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "/usr/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3.4/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
  (Driver info: OperaDriver=0.2.0 (ba47709ed9e35ce26dbd960fb5d75be104290d96),platform=Linux 3.10.0-514.2.2.el7.x86_64 x86_64)

Versions Python 3.4.5 Operadriver 0.2.2 Python bindings 3.0.2 Opera 42.0.2393.85 CentOS 7.3.1611 Not using Selenium Server Standalone.

nmnandakishore commented 7 years ago

same issue..

abdelhamidlinux5765 commented 7 years ago

hello, i am running r windows 3.4 in linux by wine and i have this issue when trying to open opera using linux for operadriver.

ghost commented 7 years ago

Hey guys, I got it working:

alan@kaiju:~ (1021)% opera --version
44.0.2510.1218
alan@kaiju:~ (1022)% operadriver --version
OperaDriver 2.27 (f61056e560d197467fd6d27c7fbd7fea572fe8bd)
alan@kaiju:~ (1023)% python3 --version                            
Python 3.5.2+
alan@kaiju:~ (1024)% ipython3

<snip>

In [1]: import selenium

In [2]: selenium.__version__
Out[2]: '3.3.1'

In [3]: from selenium import webdriver

In [4]: options = webdriver.ChromeOptions()

In [5]: options.binary_location = "/usr/bin/opera" # path to opera executable, even though it's in PATH :/

In [6]: driver = webdriver.Opera(opera_options=options) # success!

Try this.

ghost commented 7 years ago

I don't know Java or R. I'd suggest opening another issue since this is a Python thread.

wladzynski commented 7 years ago

Hi! Are you still experiencing the issue mentioned in the OP with the latest operadriver releases?

tompil commented 6 years ago

@wladzynski Could you reopen the issue? I have the same problem. Running the similar code results an error.

Traceback (most recent call last):
  File "C:\Users\tompil\Documents\selenium_opera_issue.py", line 3, in <module>
    browser = webdriver.Opera()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 78, in __init__
    service_log_path=service_log_path)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 57, in __init__
    service_log_path=service_log_path)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
  (Driver info: OperaDriver=2.32 (cfa164127aab5f93e5e47d9dcf8407380eb42c50),platform=Windows NT 10.0.16299 x86_64)

Versions: Python 3.6.1 OperaDriver 2.3.2 Python bindings 3.8.1 Opera 49.0.2725.64 MS Windows 10 Pro 10.0.16299 build 16299

duanzhijie861229 commented 6 years ago

from selenium import webdriver options = webdriver.ChromeOptions() options.binary_location = "D:\Program Files\Opera1\50.0.2762.58\opera.exe"# path to opera executable driver = webdriver.Opera(options=options) driver.get("http://www.opera.com")# success

Versions: Python 3.6 OperaDriver 2.3.3 Opera 50.0.2762.58 Windows 7

buscseik commented 6 years ago

I tried the solution that was proposed by @duanzhijie861229 and it has produced a very interesting error message. See output below:

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> options = webdriver.ChromeOptions()
>>> options.binary_location = "c:\Program Files\Opera\51.0.2830.40\opera.exe"
>>> driver = webdriver.Opera(options=options)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python36\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 78, in __init__
    service_log_path=service_log_path)
  File "C:\Python36\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 57, in __init__
    service_log_path=service_log_path)
  File "C:\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: no Opera binary at c:\Program Files\Opera).0.2830.40\opera.exe
  (Driver info: OperaDriver=2.32 (cfa164127aab5f93e5e47d9dcf8407380eb42c50),platform=Windows NT 10.0.16299 x86_64)

As you can see the "\51." in the path has been miss interpreted into ")" in the defined path "\51." is in line 5 ")" is in line 23

tompil commented 6 years ago

Use a double backslash instead of single one. \51 in a string literal is an escape sequence, which produces ')' (which has code 51 in octal representation in ASCII table). This is not good idea to hardcode the path in a script. It's more flexible to use a config file or set an environment variable.

duanzhijie861229 commented 6 years ago

something wrong happen when i upload the code"D:\\Program Files\\Opera1\\50.0.2762.58\\opera.exe" you can change your code to:options.binary_location = "c:\\Program Files\\Opera\\51.0.2830.40\\opera.exe"or options.binary_location = "c:/Program Files/Opera/51.0.2830.40/opera.exe"

buscseik commented 6 years ago

Yep, I know, I have option to use\\ or even / to avoid this problem in this example. But what I want to highlight here, this is a bug! Why opera driver/python connector does not handle this type of input on correct manner.

To put my problem into context. I use selenium in Robotframework. In that, I do not have option to define the custom path. This will be done by the Python selenium connector and it is based on system PATH.

einsteinsfool commented 6 years ago

I still have this issue with: Python 3.6.4 Operadriver 2.33 Python bindings 3.10.0 Opera 51.0.2830.40 Linux 64bit

It works with mentioned by ghost hotfix:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.binary_location = "/usr/bin/opera" # getting error without this line
browser = webdriver.Opera(options=options)
browser.get('http://seleniumhq.org/')
browser.quit()

Specifying binary location shouldn't be necessary.

Lumia1020 commented 6 years ago

thanks bro

FedFabFrat commented 5 years ago

hi, following the solution of ghost, and I am prompted the following error:

_WebDriverException: unknown error: Opera failed to start: exited normally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location C:\Users\feder\AppData\Local\Programs\Opera\launcher.exe is no longer running, so OperaDriver is assuming that Opera has crashed.) (Driver info: OperaDriver=2.42.3135 (O58),platform=Windows NT 10.0.17763 x8664)

Any ideas?

UzaeirAzhar commented 5 years ago

For me same error appeared. But then I changed my binary location to e.g:

C:\\Users\\UK\\AppData\\Local\\Programs\\Opera\\58.0.3135.65\\opera.exe

Then it works. Check your location and try to replace it.

ikostan commented 5 years ago

Hi all. I just wonder is there any hope that one day this issue will be fixed and we will no longer required to specify options.binary_location? I mean, all other drivers know how to find the binary by the default install path... Thanks.