在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 Files\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "D:\Program Files\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "D:\Program Files\Python36\lib\subprocess.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 Files\Python36\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "D:\Program Files\Python36\lib\site-packages\selenium\webdriver\common\service.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 Files\Python36\ 添加到系统环境变量Path路径下,将chromedriver.exe文件放到D:\Program Files\Python36\ 目录下即可;

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

python脚本中selenium启动浏览器报错os.path.basename(self.path), self.start_error_message) selenium.common.excep的更多相关文章

  1. Shell脚本中"command not found"报错处理

    字符串的定义与赋值 # 定义STR1变量,值为abc STR1 = "abc"(错误写法) STR1="abc"(正确写法) 在编写java代码时会考虑到格式化 ...

  2. python+selenium打开浏览器报错问题

    报关键字,升级selenium版本 若打开IE浏览器,停在IE界面,无法跳转对应的地址,设置一下IE的页面缩放,设置为100%

  3. selenium 打开浏览器报错java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.addArguments([Ljava/lang/String;)

    java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.addArguments([Ljava/lang/Strin ...

  4. 命令行可以执行python脚本,jenkins里执行报错:cannot find Chrome binary

    “selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary”这个 ...

  5. IDEA中debug启动tomcat报错。Error running t8:Unable to open debugger port(127.0.0.1:49225):java.net.BindException"Address alread in use:JVM_Bind"

    解决办法: 1,如下图打开项目配置的tomcat的“Edit Configurations...” 2,打开“Startup/Connection”--------"Debug"- ...

  6. 在datagrid中,IE浏览器报错:SCRIPT5007: 无法获取属性“rowspan”的值: 对象为 null 或未定义

    项目总采用datagird时,产生界面如下图原本标题上有功能按钮,此时消失   错误:SCRIPT5007: 无法获取属性"rowspan"的值: 对象为 null 或未定义, 造 ...

  7. springcloud中config启动时候报错Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'config.info' in value "${config.info}"

    -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jm ...

  8. $Django 多表操作(增删改查,基于双下划线,对象的查询) 在Python脚本中调用Django环境

    在Python脚本中调用Django环境. import osif __name__ == '__main__': os.environ.setdefault("DJANGO_SETTING ...

  9. 解决selenium 启动ie浏览器报错:Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones

    启动ie代码: System.setProperty("webdriver.ie.driver", "bin/IEDriverServer.exe"); Web ...

随机推荐

  1. spring配置文件拆分策略及方法

    一.拆分策略 如果一个开发人员负责一个模块,我们采用公用配置(包括数据源.事务等)+每个系统模块一个单独配置文件(包括Dao.Service.Web控制器)的形式 如果是按照分层进行的分工,我们采用公 ...

  2. CSS3点击波浪按钮特效

    在线演示 本地下载

  3. Skills CodeForces - 613B (双指针)

    大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $cm$ ...

  4. Linux下用OTL操作MySql(包含自己封装的类库及演示样例代码下载)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/ClamReason/article/details/23971805 首先重点推荐介绍otl介绍及使 ...

  5. linux增加swap大小

    参考自:https://blog.csdn.net/ssrmygod/article/details/70157716 我在centos6.5上照着操作成功了首先查一下目前swap的大小: [root ...

  6. Kong/Konga - Docker容器化安装

    1.0 安装kong + postgresDB docker network create kong-net docker pull postgres:latest docker run -d --n ...

  7. log4j2配置文件xml详细了解

    log4j2配置文件xml详细了解 详细参考:https://www.cnblogs.com/new-life/p/9246143.html log4j 2.x版本不再支持像1.x中的.propert ...

  8. colaui基础

    监控 c-watch // 监控的方法函数 on 监控的参数名字 div(c-watch="fun on style" c-bind="styles") // ...

  9. 错误信息 NSError

    一.获取系统的错误信息 比如移动文件时,获取文件操作错误: NSError *e = nil;[[NSFileManager defaultManager] moveItemAtPath:source ...

  10. C语言的unsigned做双目运算符的奇怪问题

    首先看代码: #include <stdio.h> void main() { ; unsigned ; ) { printf("%d-%d=%d,大于0", num1 ...