SleepyLuc
SleepyLuc

Reputation: 3

Python Selenium Error: Cannot find Opera binary

i'm trying out Python Selenium with my main browser, Opera, but i get a massive error when i execute the script, here's the python script:

from selenium import webdriver
path = r"C:\Users\sleep\Programs\operadriver_win64\operadriver.exe"
driver = webdriver.Opera(executable_path=path)
driver.get('https://youtube.com')

And here's the error:

Traceback (most recent call last):
  File "C:\Users\sleep\Programs\Status-Entrega\main.py", line 6, in <module>
    driver = webdriver.Opera(executable_path=r'C:\Users\sleep\Programs\operadriver_win64\operadriver.exe')
  File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 79, in __init__
    OperaDriver.__init__(self, executable_path=executable_path,
  File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 55, in __init__
    ChromiumDriver.__init__(self,
  File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\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=91.0.4472.77 (1cecd5c8a856bc2a5adda436e7b84d8d21b339b6-refs/branch-heads/4472@{#1246}),platform=Windows NT 10.0.19042 x86_64)

How can i fix this?

Upvotes: 0

Views: 410

Answers (2)

Question-er XDD
Question-er XDD

Reputation: 767

This link may help: https://github.com/operasoftware/operachromiumdriver/blob/master/examples/desktop.py

import time

from selenium import webdriver
from selenium.webdriver.chrome import service


webdriver_service = service.Service('path/to/operadriver')
webdriver_service.start()

driver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)

driver.get('https://www.google.com/')
input_txt = driver.find_element_by_name('q')
input_txt.send_keys('operadriver\n')

time.sleep(5) #see the result
driver.quit()

Upvotes: 0

H&#252;seyin Avcı
H&#252;seyin Avcı

Reputation: 66

can you try this :

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

options = Options()
options.binary_location = r'C:\opera.exe path'
driver = webdriver.Opera(opera_options = options, 
executable_path=r'C:\operadriver.exe path')

it might work, don't forget one is the opera path and one is the operadriver path

Upvotes: 2

Related Questions