Mac python+selenium+chrome 配置及报错

平台:mac + pycharm

  1. 安装selenium.
    可以在pycharm中安装,也可以pip install
  2. 安装chrome driver.
    下载地址:http://chromedriver.storage.googleapis.com/index.html
    将chromedriver放在/usr/local/bin目录下

执行以下代码

from selenium import webdriver
import time

driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')
time.sleep(3)
driver.quit()

报错:selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
报错可能的原因是Chromedriver的路径不对,或者是chrome的路径不对。
由于chromedriver已经放在了/usr/local/bin下,如下图确认没有问题。
Mac python+selenium+chrome 配置及报错_第1张图片
然后发现我电脑上的chrome安装的路径有问题,将它卸载后,从官网https://www.google.cn/chrome/ 重新下载安装之后,它会自动将安装的chrome.app放在Applications下,再运行程序就没有问题了。
程序找chrome的时候,默认是从applocations目录中找的。

你可能感兴趣的:(自动化测试)