编程语言
首页 > 编程语言> > Python+selenium运行出错‘Application‘ executable may have wrong permissions.

Python+selenium运行出错‘Application‘ executable may have wrong permissions.

作者:互联网

最近在学习Python的自动化测试,需要用到selenium,于是开始安装selenium,并简单运行

我的环境:

win7+chrome+Python2.7

安装selenium 很简单,直接pip install selenium,等待安装完成即可

然后通过网上学习需要为对应的浏览器安装驱动,而且驱动的版本要跟浏览器版本对应,浏览器驱动下载及版本对应请参考如下地址:

版本对应参照  http://blog.csdn.net/huilan_same/article/details/51896672

驱动下载镜像网站  http://npm.taobao.org/mirrors/chromedriver/

下载完成之后,将解压之后的chromedriver.exe放置浏览器安装目录,我的是C:\Program Files (x86)\Google\Chrome\Application,然后将这个目录添加到环境变量中,否则会出现如下错误:

WebDriverException: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home


在运行脚本还是出现如上错误,网上百度,说是创建webdriver是需要将chromedriver.exe的路径传递进去,如下操作

driver = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\Application')

但是运行后又出现了新的错误,如下所示:

WebDriverException: 'Application' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

网上百度,发现没有跟我一样的,网上的都是‘webdriber’executable may have wrong permissions类似的,原因都是未加环境变量,但是我加了环境变量

再分析错误原话,翻译过来“可执行文件Application可能有错误的许可”,发现Application有问题啊,这是个目录,不是可执行文件啊,在回头看需要传递路径进webdriber的文章,发现需要传递的是驱动,而不仅仅是路径,加上驱动名后

driver = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\Application\chromedriver')

正常运行了


   
  1. # coding = utf-8
  2. from selenium import webdriver
  3. driver = webdriver.Chrome( 'C:\Program Files (x86)\Google\Chrome\Application\chromedriver')
  4. driver.get( 'http://www.baidu.com')
  5. print driver.title
  6. driver.quit()


标签:webdriver,executable,Application,may,driver,selenium,chromedriver,Python,Chrome
来源: https://blog.csdn.net/weixin_43135165/article/details/122755479