Selenium是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。本文主要讲述的是web测试中Selenium 3使用的问题集以及解决方案。
1. 无法启动FireFox--geckodriver
运行 driver=webdriver.Firefox()
运行报错:
Exception AttributeError: "'Service' object has no attribute 'process'" in
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executabl needs to be in PATH.
解决方案:
下载https://github.com/mozilla/geckodriver/releases 最新版,把geckodriver.exe加到系统path路径下,即可解决此问题。
2. Firefox默认安装,但找不到启动路径
selenium.common.exceptions.WebDriverException: 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
解决方案:
加入这几行代码就可以解决。
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary # Create a new instance of the Firefox driver binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe') driver = webdriver.Firefox(firefox_binary=binary)
3. 无法启动IE 的问题
driver = webdriver.Ie()
selenium.common.exceptions.WebDriverException: Message: 'IEDriverServer.exe' executable needs to be in PATH. Please download from http://selenium-release.storage.googleapis.com/index.html and read up at https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
Exception AttributeError: "'Service' object has no attribute 'process'" in
解决方案:
这里下载驱动: http://selenium-release.storage.googleapis.com/index.html?path=3.0/,把IEDriverServer.exe放到系统path目录即可。
【推荐课程:Python视频课程】
以上是web自动化测试(一)Selenium 3使用系列问题集的详细内容。更多信息请关注PHP中文网其他相关文章!