Mac系统安装[chromedriver]和[geckodriver]

在进行Web自动化测试的时候,配置环境是比较重要的一个环节,而往往我们进行自动化测试的时候离不开三个环境,Windows/Linux/Mac,本篇将详细介绍在MAC系统上如何安装浏览器驱动

第一种方式

在Mac系统上有一个很重要的工具就是brew,它就像我们在某Linux上常用的yum一样好用,因此在Mac系统上安装浏览器驱动,我们先看brew

brew install chromedriver

DY@MacBook-Pro bin$brew install chromedriver
Error: No available formula with the name "chromedriver" 
It was migrated from homebrew/core to homebrew/cask.
You can access it again by running:
  brew tap homebrew/cask
And then you can install it by running:
  brew cask install chromedriver
DY@MacBook-Pro bin$brew cask install chromedriver
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 4175, done.
remote: Counting objects: 100% (4175/4175), done.
remote: Compressing objects: 100% (4153/4153), done.
remote: Total 4175 (delta 27), reused 760 (delta 19), pack-reused 0
Receiving objects: 100% (4175/4175), 1.33 MiB | 816.00 KiB/s, done.
Resolving deltas: 100% (27/27), done.
Tapped 1 command and 4077 casks (4,185 files, 4.2MB).
==> Satisfying dependencies
==> Downloading https://chromedriver.storage.googleapis.com/2.44/chromedriver_ma
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'chromedriver'.
==> Installing Cask chromedriver
==> Creating Caskroom at /usr/local/Caskroom
==> We'll set permissions properly so we won't need sudo in the future.
Password:
Sorry, try again.
Password:
==> Linking Binary 'chromedriver' to '/usr/local/bin/chromedriver'.
?  chromedriver was successfully installed!

brew install gecodirver

DY@MacBook-Pro bin$brew install geckodriver
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
libbladerf

==> Downloading https://homebrew.bintray.com/bottles/geckodriver-0.23.0.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring geckodriver-0.23.0.high_sierra.bottle.tar.gz
?  /usr/local/Cellar/geckodriver/0.23.0: 7 files, 6.7MB

使用brew安装好后,省很多事情,甚至软连接都已经自动完成了,然后在命令行验证一下浏览器驱动是否成功安装,启动命令行,进入python命令行模式

davieyang@davieyangs-MacBook-Pro ~ % python3
Python 3.7.6 (default, Dec 27 2019, 09:51:21) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> driver = webdriver.Chrome()

浏览器正常启动表示浏览器驱动安装成功

第二种方法

从谷歌浏览器驱动竞相地址chromedriver下载驱动文件
从火狐浏览器驱动地址geckodriver下载驱动文件
然后在定义浏览器驱动的时候,直接给函数加上executable_path参数即可

chrome_driver = webdriver.Chrome(executable_path=)

或者将下载下来的geckodriver,chromedriver放在/usr/local/bin目录下 ,也就无需在代码中指定路径了

发布了207 篇原创文章 · 获赞 124 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/dawei_yang000000/article/details/105310364
今日推荐