51Testing软件测试论坛

标题: Mac配置selenium3自动化测试环境 [打印本页]

作者: 测试积点老人    时间: 2018-12-18 15:34
标题: Mac配置selenium3自动化测试环境

系统环境 mac python3.6

pip instal selenium #安装selenium模块,默认是最新的ye可以pip instal selenium==版本号

brew install geckodriver #下载安装geckodriver

或者直接去selenium官网下载https://github.com/mozilla/geckodriver/releases

geckodriver-v0.20.0-macos.tar.gz解压到指定目录,或者配置到python环境中/usr/local/bin。

Firefox浏览器版本59.0.2

报错

elenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH,是因为geckodriver的没有在环境变量中识别到


报错

selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities,是因为浏览器的版本和驱动的版本不一致

测试一下

  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. from selenium import webdriver
  4. import time
  5. #driver = webdriver.Firefox(executable_path="/usr/local/bin/geckodriver")
  6. driver = webdriver.Firefox(executable_path="/Users/wang/Downloads/geckodriver")
  7. driver.get("http://www.baidu.com")
  8. driver.find_element_by_id("kw").send_keys("测试")
  9. driver.find_element_by_id("su").click()
  10. time.sleep(30)
  11. driver.quit()
复制代码







欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2