selenium.common.exceptions.WebDriverException:消息:未

2019-11-05 05:54发布

我只是试图让一个简单的Python脚本工作,这应该只打开谷歌。

我安装了硒具有画中画和放置operadriver,从硒页面下载到我的Python路径。 还看了很多关于它的视频,但我不能找到一个解决办法..

下面的代码:

from selenium import webdriver
import time

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

错误:

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)

Answer 1:

此错误消息...

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)

......意味着Opera浏览器的二进制文件未在规定的位置找到。

你的主要问题是Opera浏览器在默认位置未安装。 所以,你需要提及其中的Opera浏览器的安装步骤如下位置的绝对路径

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')


文章来源: selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary with OperaDriver Selenium and Python