python+selenium自动化测试实战-问题与解决

题一:使用IDLE执行自动化脚本时报错“Message: 'geckodriver' executable needs to be in PATH”

原因:缺少火狐浏览器驱动程序geckodriver,需要在官网下载解压后将geckodriver.exe程序放到python的根目录下,然后重启IDLE再次执行就可以了。

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

放置路径:我的是D:\Program Files\python37下

火狐浏览器驱动下载地址:https://github.com/mozilla/geckodriver/releases

谷歌浏览器驱动下载地址:http://chromedriver.storage.googleapis.com/index.html

 

问题二:从文件读取数据时,文件路径问题

例:source=open("D:\autotest\seleniumDemo\script\data","r")

上面的写法运行时会报找不到文件,因为\是转义字符,要输出\需要在前面在加个\转义一下才可以,或者是在路径前加一个r,让python自动处理字符串,因此路径的正确写法如下

正确写法一:source=open("D:\\autotest\\seleniumDemo\\script\\data","r")

正确写法二:source=open(r"D:\autotest\seleniumDemo\script\data","r")

 

问题三:使用免安装版本Firefox浏览器时,运行脚本时启动不了浏览器

下载了一个免安装的firefox浏览器,直接解压在了本地D盘的某个路径下,然后运行写好的脚本,结果发现启动不了浏览器

报错信息:Expected browser binary location, but unable to find binary in default location

原因:找不到浏览器的位置

解决办法:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary(r"D:\Program Files (x86)\firefox51\firefox-sdk\bin\firefox.exe")

driver = webdriver.Firefox(firefox_binary=binary)

 

 

posted @ 2020-07-20 17:36  —沐雨乘风—  阅读(318)  评论(0编辑  收藏  举报