最近在Ubuntu上跑UI自动化测试脚本,遇到下面几个问题,在这里分享一下。
1.FileNotFoundError: [Errno 2] No such file or directory: ‘geckodriver’
出现这个报错是没有找到驱动,这里需要安装对应的驱动。git下载地址:https://github.com/mozilla/geckodriver/releases
下载完成解压文件上传到Linux服务器上,安装到/usr/local/bin目录。
2.PermissionError: [Errno 13] Permission denied: ‘geckodriver’
出现这个报错是权限不够,找到geckodriver驱动安装的目录,修改权限就行,我这里直接全选。
3.selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no ‘moz:firefoxOptions.binary’ capability provided, and no binary flag set on the command line
这个报错是找不到浏览器,如果在Linux上没有安装浏览器的需要先安装,安装过找不到就需要在python脚本里面加上浏览器的安装路径。
例如:webdriver.Firefox(‘/home/firefox’)