python版本为3.7
- 安装selenium
pip3 install selenium
- 安装geckodriver
brew install geckodriver
- 设置配置文件
vim ~/.bash_profile
export PATH=$PATH:/usr/local/Cellar/geckodriver/0.24.0/bin
- 使配置生效
source ~/.bash_profile
- 编写第一个测试脚本
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get(url="http://www.baidu.com")
print(driver.title)
time.sleep(1)
driver.find_element_by_id('kw').send_keys('selenium2')
time.sleep(2)
driver.find_element_by_id('su').click()
time.sleep(3)
driver.quit()
print("{}test program".format("我的第一个"))