zoukankan      html  css  js  c++  java
  • python脚本中selenium启动浏览器报错os.path.basename(self.path), self.start_error_message) selenium.common.excep

    在python脚本中,使用selenium启动浏览器报错,原因是未安装浏览器驱动,报错内容如下:

    # -*- coding:utf-8 -*-
    from selenium import webdriver

    driver = webdriver.Firefox()
    driver.get("http://www.baidu.com")

    报错提示如下所示:

    Traceback (most recent call last):
    File "D:Program FilesPython36libsite-packagesseleniumwebdrivercommonservice.py", line 76, in start
    stdin=PIPE)
    File "D:Program FilesPython36libsubprocess.py", line 709, in __init__
    restore_signals, start_new_session)
    File "D:Program FilesPython36libsubprocess.py", line 997, in _execute_child
    startupinfo)
    FileNotFoundError: [WinError 2] 系统找不到指定的文件。

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "D:/Program Files/Python36/baidu.py", line 4, in <module>
    driver = webdriver.Firefox()
    File "D:Program FilesPython36libsite-packagesseleniumwebdriverfirefoxwebdriver.py", line 164, in __init__
    self.service.start()
    File "D:Program FilesPython36libsite-packagesseleniumwebdrivercommonservice.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
    selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.


    解决方案:安装Chrome浏览器驱动
    1.下载 chromedriver_win32.zip,根据浏览器版本下载对应的压缩包;
    下载地址:https://sites.google.com/a/chromium.org/chromedriver/downloads

    2.解压后将chromedriver.exe文件放到系统环境变量Path路径下,例如:已将D:Program FilesPython36 添加到系统环境变量Path路径下,将chromedriver.exe文件放到D:Program FilesPython36 目录下即可;

    3.将Chrome替换掉原脚本中的Firefox,保存文件并运行。

    # -*- coding:utf-8 -*-
    from selenium import webdriver

    driver = webdriver.Chrome()
    driver.get("http://www.baidu.com")

    driver.find_element_by_id("kw").send_keys("Selenium2")
    driver.find_element_by_id("su").click
    driver.quit()

     

     

     



    原文:https://blog.csdn.net/weixin_44612439/article/details/87983282

  • 相关阅读:
    Web应用程序使用Hibernate
    Hibernate使用注释
    Hibernate入门程序
    Hibernate体系结构
    Spring MVC文件上传教程
    Spring MVC配置静态资源和资源包教程
    Spring MVC4使用Servlet3 MultiPartConfigElement文件上传实例
    Spring4 MVC文件下载实例
    Spring4 MVC+Hibernate4 Many-to-many连接表+MySQL+Maven实例
    Spring4 MVC+Hibernate4+MySQL+Maven使用注解集成实例
  • 原文地址:https://www.cnblogs.com/z3286586/p/11096117.html
Copyright © 2011-2022 走看看