由于selenium3需要的Safari版本为10以上,Safari是和系统一起升级的,我又不想升级系统。
所以就选了FireFox。
首先安装FireFox
进入官网下载安装,将FireFox拖到Applications中;
然后安装selenium的FireFox接口geckodriver
,进入官网下载Mac版,然后解压移到/usr/bin or /usr/local/bin目录;
mv geckodriver /usr/local/bin
最后安装selenium;
pip install selenium
最后测试一下;
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()