python selenium自动化登录错误解决

from selenium import webdriver
browser = webdriver.Firefox()

browser.get(‘http://www.baidu.com/‘)

 错误代码

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Python34\lib\subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1114, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:/Python项目/numpy/function_args.py", line 3, in <module>
    browser = webdriver.Firefox()
  File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in __init__
    self.service.start()
  File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH.

  网上找到很多方法添加路径

from selenium import webdriver
browser = webdriver.Firefox("C:\Program Files (x86)\Mozilla Firefox\firefox.exe")

添加PATH环境变量,还是报错,

后来在stackoverflow找到答案

https://stackoverflow.com/questions/40437226/selenium-wont-work-with-firefox-or-chrome

Firefox和Chrome,需要下载geckodriver / chromedriver。这些驱动程序是您安装的浏览器与selenium之间进行通信所必需的。所以你需要:

firefox驱动下载地址: https://github.com/mozilla/geckodriver/releases

chrome驱动下载地址:  https://sites.google.com/a/chromium.org/chromedriver/downloads

1.  安装python(pip install selenium)selenium

2. 下载你使用的浏览器的驱动程序(chromedriver,geckodriver,operadriver等)

将所下载的驱动geckodriver.exe文件路径添加到代码

谷歌  : driver = webdriver.Chrome(executable_path=‘/path/to/chromedriver.exe‘)

火狐:   driver = webdriver.Firefox(executable_path=‘/opt/geckoDriver/geckodriver.exe‘)

完整代码:

from selenium import webdriver

#browser = webdriver.Firefox()
browser = webdriver.Firefox(executable_path=r‘C:\Users\Administrator\Desktop\bs\geckodriver.exe‘)
browser.get(‘http://www.baidu.com/‘)
# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), ‘geckodriver‘))
binary = FirefoxBinary(r‘C:\Program Files (x86)\Mozilla Firefox\firefox.exe‘)
browser = webdriver.Firefox(firefox_binary=binary,executable_path=gecko+‘.exe‘)
browser.get(‘http:///www.google.com‘)
browser.close()
时间: 2024-08-06 04:31:05

python selenium自动化登录错误解决的相关文章

琉璃小屋-用python+selenium 自动化登录后台系统

一 Selenium介绍 Selenium也是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE.Mozilla Firefox.Mozilla Suite等. "Selenium测试直接运行在浏览器中,就像真正的用户在操作一样" 二Selenium安装 pip install selenium== 3.141.0[版本号] pip install -U selenium 三编写自动化登录脚本 from seleni

Python+Selenium自动化模拟用户登录(备注:记录一次强行卸载rpm依赖包,引发的rpm、yum等命令异常,无法远程xftp工具)

近期在摸索Python+Selenium自动化,实现模拟用户登录搜索等操作,反馈相关日志,再交由Zabbix分析,监控页面访问是否正常. 期间需要对Linux火狐浏览器进行升级,由于生产环境为内网环境,无法使用yum进行升级.本想在外网环境下使用Docker进行安装,然后打成镜像后迁移到内网环境.但由于系统为Red Hat 6.4对Docker支持较差,故在外网将相关依赖包下载后进行安装. 外网环境下,下载Firefox及相关依赖组件相关操作.         1.更新本地yum源为阿里yum源

python+selenium自动化环境搭建之后,能打开firefox,却不能执行自动化操作

python+selenium自动化环境搭建之后,选择执行,能够打开firefox,但是却不能继续执行后续操作.原因是selenium的版本与firefox的版本不兼容. 解决办法: 1.将firefox降到与selenium相对应的版本.例如我使用selenium版本是3.3.3,那我对应的firefox版本是52.0.2,如果firefox继续升级,也会出现不兼容的情况.建议可以在firefox的工具--选项--高级中设置为不检查更新,以免软件自动更新出现问题. 2.安装该浏览器版本对应的g

python + selenium自动化环境常见问题小结

python + selenium自动化环境常见问题小结 (1)操作Windows窗口有三种方法,一是使用AutoIT软件生成exe程序,再用系统命令调用:二是使用SendKeys类模拟键盘操作(只能定位当前的焦点):三是使用pywinauto组件(win32gui) (2)pywinauto包只支持到python2.6版本.SendKeys包在python3.0版本上也无法安装成功. (3)执行完用例进行断言校验时,一般会获取元素的text属性,有时候在页面上查看元素有text值,而获取的为空

Python+selenium自动化公共逻辑步骤封装

开篇 个人博客"Python+selenium的GUI自动化实现"提到的chrome与IE浏览器调用插件已上传至51CTO下载,对应链接分别为:chrome,http://down.51cto.com/data/2171584:IE,http://down.51cto.com/data/2171585:有需要的直接下载即可:  正文 关于自动化,其实质就是用机器操作代替手工执行,从而减少人力投入.节约项目运营成功.优秀的自动化框架,可能的一个发展过程,前期自动化用例写作实现过程,可能需

如何写好Python+Selenium自动化?

哈喽,各位客官好,今天我给大家讲讲如何使用Python+Selenium做自动化测试,楼主在做开发测试之前做得java开发,由于种种原因,楼主转成了开发测试,接着又自学了脚本语言linux和python,对于这两门脚本,我是非常的喜欢,为什么呢,因为用起来效率太高了,所以楼主弃java转python,至于为什么,不做多解释,你懂得.接下来我将给各位讲讲如何用python+selenium自动化 1,什么是selenium selenium是一个开源的自动化测试框架,主要适用WEB测试,可以支持多

python+selenium自动化环境配置及使用实例

一.搭建环境相关地址以及相关模块下载地址 1.#各个浏览器驱动下载地址: https://www.cnblogs.com/nancyzhu/p/8589764.html 2.#sublime+python+selenium自动化配置教程: http://python.tedu.cn/know/289803.html 3.#html测试报告: https://github.com/defnngj/HTMLTestRunner         http://www.testpub.cn/t/213

python selenium自动化屏蔽chrome“正受到自动化测试软件的控制”、“开发者模式”、“保存密码提示”

python selenium自动化屏蔽chrome“正受到自动化测试软件的控制”.“开发者模式”.“保存密码提示” from selenium import webdriver option = webdriver.ChromeOptions() #屏蔽自动化受控提示 && 开发者提示 option.add_experimental_option("excludeSwitches", ['enable-automation', 'load-extension']) #

Python + Selenium 实现登录Office 365

最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解,据说是用了Google的IP,whatever……) 试图研究一下Selenium和WebDriver的关系,看了官方的介绍,先摘录一段有趣的内容: Jump to 2008. The Beijing Olympics mark China’s arrival as a global power,