在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. 笛卡尔树--牛客第四场(sequence)

    思路: O(n)建一颗笛卡尔树,再O(n)dfs向上合并答案就行了. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include &l ...

  2. # C++中对PI的引用

    #include <iostream> #include <cmath> using namespace std; int main(){ printf("%.10l ...

  3. 用python操作mysql数据库

    数据库的安装和连接 PyMySQL的安装 pip install PyMySQL python连接数据库 import pymysql db = pymysql.connect("数据库ip ...

  4. Docker 镜像与容器管理

    镜像与容器简介 Docker的大部分操作都围绕着它的三大核心概念:镜像.容器.仓库而展开.因此,准确把握这三大核心概念对于掌握Docker技术尤为重要,在docker中,我们重点关注的就是镜像和容器了 ...

  5. @RequestMapping-限定参数映射

    限定参数映射 测试:

  6. java实现生产者和消费者问题

    Java实现生产者和消费者问题 欢迎访问我的个人博客,获取更多有用的东西 链接一 链接二 也可以关注我的微信订阅号:CN丶Moti

  7. H5的video标签在网页上播放MP4视频时只有声音没有画面

    最近做一个项目时,发现mp4文件播放时没有图像,只有声音,代码检查了N次,都没有问题,就算是直接使用网上的实例代码,也只能播放实例视频,mp4文件绝对路径,相对路径也都试了,还是不能播放我的mp4. ...

  8. 帝国cms所有一级栏目遍历,如果有子栏目的话,遍历出来

    所有一级栏目遍历,如果有子栏目的话,遍历出来. 注意下方的bclassid是可以改变的.可以改成自己想要设置的父栏目id. 遍历所有栏目,如果有二级栏目的话显示 [e:loop={"sele ...

  9. Centos7下安装ZooKeeper

    1.下载源码 zookeeper 需要jdk的支持,需要先安装jdk 官网下载地址: http://mirrors.hust.edu.cn/apache/zookeeper/ 选择最新的版本进行下载 ...

  10. oracle重置dba用户密码

    1.进入sqlplus里面: [oracle@master ~]$ sqlplus / as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Tue ...