I just tried to get an easy Python script to work, which should only open up google.

I installed selenium with pip and placed the operadriver, downloaded from the selenium page, into my python path. Also watched many videos about it, but I can't find a solution..

Here's the code:

from selenium import webdriver
import time

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

The error:

Traceback (most recent call last):
  File "C:/Users/Tom/AppData/Local/Programs/Python/Python37-32/Scripts/automate.py", line 4, in <module>
    driver = webdriver.Opera()
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 83, in __init__
    service_log_path=service_log_path)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 62, in __init__
    keep_alive=keep_alive)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\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: cannot find Opera binary
  (Driver info: OperaDriver=2.40 (a50783a565882ef2022bea655e8560f37ecf8afe),platform=Windows NT 6.1.7601 SP1 x86_64)
2

There are 2 best solutions below

0
On

The simple solution for me: I have a Feedscode folder where my chromedriver.exe and my operadriver.exe reside in my downloads folder where I run the file.ipynb files.

The error is pretty obvious it is looking in the wrong place for the opera.exe this issue started for me after opera updated to 73.0.3856.257_0 this is the latest opera folder update as of 12/14/2020.

What I did to fix opera was I took C:\Users\your_user_name_here\AppData\Local\Programs\Opera\73.0.3856.257_0 folder and simply copied the folder 73.0.3856.257_0 to my downloads\feedscode folder I then copied my .ipynb files and my operadriver.exe and chromedriver.exe files to the 73.0.3856.257_0 folder then I made this one change before I ran the process.

chrome_path = "C:\Users\User_name_here\Downloads\FeedsCode\73.0.3856.257_0\operadriver.exe"

Now the process works as expected.

So the error clearly is due to the fact it is looking for opera.exe in the folder that the operadriver.exe is located in. You have 2 options 1. Wait for a fix or 2. Do as I have shown above.

I am sure this will help many as the original answer here did not work for me everyone enjoy.

Note the chromedriver.exe does not have this problem, so you can simply use chromedriver.exe instead of operadriver.exe. I also notice in the Opera update when we run the process it will work fine as long as the process window remains on the screen if we go to another task window it will stop until you open the process screen back up. THIS DOES NOT HAPPEN with chromedriver.exe only the latest operadriver.exe and Opera update as of 12/14/2020.

Note there is an advantage to my suggested fix and that is the Opera Browser will not automatically update since we copied the entire 73.0.3856.257_0 folder to a different location you would have to copy the latest Opera updated folder manually, so you won't be stung by an update unexpectedly.

0
On

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
  (Driver info: OperaDriver=2.40 (a50783a565882ef2022bea655e8560f37ecf8afe),platform=Windows NT 6.1.7601 SP1 x86_64)

...implies that the Opera Browser binary wasn't found at the required location.

Your main issue is the Opera Browser is not installed at the default location. So you need to mention the absolute path of the location where Opera Browser is installed as follows:

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

options = Options()
options.binary_location = r'C:\path\to\opera.exe'
driver = webdriver.Opera(opera_options = options, executable_path=r'C:\Utility\BrowserDrivers\operadriver.exe')
driver.get('http://www.google.com')