【问题标题】:Drive Opera with selenium python使用 selenium python 驱动 Opera
【发布时间】:2015-09-12 08:12:20
【问题描述】:

我添加到我的环境变量中

SELENIUM_SERVER_JAR = C:\selenium_drivers\selenium-server-standalone.jar

我在这里下载的 http://selenium-release.storage.googleapis.com/index.html?path=2.46/

Python 脚本:

from selenium import webdriver

webdriver.Opera()

输出:

13:37:37.906 INFO - Launching a standalone Selenium Server
13:37:38.104 INFO - Java: Oracle Corporation 25.45-b02
13:37:38.104 INFO - OS: Windows 8 6.2 x86
13:37:38.132 INFO - v2.46.0, with Core v2.46.0. Built from revision 87c69e2
13:37:38.269 INFO - Driver class not found: com.opera.core.systems.OperaDriver
13:37:38.275 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
13:37:38.630 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:53024/wd/hub
13:37:38.631 INFO - Selenium Server is up and running
13:37:47.892 INFO - Executing: [new session: Capabilities [{browserName=opera, javascriptEnabled=true, version=, platform=ANY}]])
13:37:47.907 INFO - Creating a new session for Capabilities [{browserName=opera, javascriptEnabled=true, version=, platform=ANY}]
Started InternetExplorerDriver server (32-bit) 2.43.0.0
Listening on port 43192
13:37:51.090 INFO - Done: [new session: Capabilities [{browserName=opera, javascriptEnabled=true, version=, platform=ANY}]]

我希望 jar 定义所有内容,为什么找不到 Driver 类?

【问题讨论】:

    标签: python selenium opera


    【解决方案1】:

    下面的代码在以下设置中对我有用。希望这会有所帮助。

    • Python:3.4.0
    • 歌剧:42.0.2393.94
    • 硒:3.0.2
    • Chrome 驱动程序:2.27.440174

      import os
      
      from selenium import webdriver
      from selenium.webdriver.common import desired_capabilities
      from selenium.webdriver.opera import options
      
      _operaDriverLoc = os.path.abspath('E:\\Envs\\PySelEnv\\selserver\\chromedriver.exe')  # Replace this path with the actual path on your machine.
      _operaExeLoc = os.path.abspath('E:\\Program Files\\Opera\\42.0.2393.94\\opera.exe')   # Replace this path with the actual path on your machine.
      
      _remoteExecutor = 'http://127.0.0.1:9515'
      _operaCaps = desired_capabilities.DesiredCapabilities.OPERA.copy()
      
      _operaOpts = options.ChromeOptions()
      _operaOpts._binary_location = _operaExeLoc
      
      # Use the below argument if you want the Opera browser to be in the maximized state when launching. 
      # The full list of supported arguments can be found on http://peter.sh/experiments/chromium-command-line-switches/
      _operaOpts.add_argument('--start-maximized')   
      
      self._browserDriver = webdriver.Chrome(executable_path = _operaDriverLoc, chrome_options = _operaOpts, desired_capabilities = _operaCaps)
      

    【讨论】:

      【解决方案2】:

      根据您的问题,您似乎正在使用 Opera 12 及更早版本的旧驱动程序。假设您尝试使用最新版本的 Opera,您需要使用以下站点提供的驱动程序:OperaChromiumDriver

      该站点列出了我已经确认可以在我的机器上打开和驱动 Opera 的示例 python 代码:Python Examples for OperaChromiumDriver

      import time
      
      from selenium import webdriver
      from selenium.webdriver.chrome import service
      
      
      webdriver_service = service.Service('C:\\Users\\Kris\\Downloads\\WinPython-32bit-2.7.9.2\\operadriver.exe')
      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()
      

      编辑: 查看 selenium 的更改日志,似乎在 2.45 之后停止了对基于 Presto 的 Operas 的支持,这就是您收到错误消息的原因:CHANGELOG

      【讨论】:

        【解决方案3】:
        from selenium import webdriver
        
        driver=webdriver.Chrome('C:\\Users\\abc\\Projects\\TestProject\\operadriver.exe')
        
        driver.get('https://www.google.com/')
        

        /*

        只需给出operadriver.exe的位置...如上它将打开Opera浏览器...而不是chrome浏览器


        你可以在这里下载opera驱动:https://github.com/operasoftware/operachromiumdriver

        */

        【讨论】:

          【解决方案4】:

          我使用webdriver_manager package 用 selenium 驱动 Opera。

          安装:

          pip install webdriver-manager
          

          设置:

          from selenium import webdriver
          from webdriver_manager.opera import OperaDriverManager
          
          driver = webdriver.Opera(executable_path=OperaDriverManager().install())
          

          用途:

          driver.get("https://www.google.com")
          

          【讨论】:

            猜你喜欢
            • 2014-09-03
            • 2020-05-05
            • 1970-01-01
            • 2021-01-22
            • 2018-04-30
            • 1970-01-01
            • 2017-07-30
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多