1. 程式人生 > >selenium3.0.2版本以及Firefox瀏覽器的相容和相關問題

selenium3.0.2版本以及Firefox瀏覽器的相容和相關問題

selenium的安裝方法:1、安裝好python的pip工具後,在cmd下,輸入pip install selenium==3.0.2 回車2、下載selenium的離線安裝包,訪問網址https://pypi.python.org/pypi/delenium,選擇副檔名為gz的原始碼包進行下載,下載完成後得到一個selenium-3.0.2.tar.gz離線安裝檔案,解壓該檔案到任意目錄,cmd下通過cd命令將當前的工作目錄切換到‘setup.py’檔案所在目錄,然後cmd下執行python setup.py install 命令進行安裝,安裝成功後,在cmd下輸入python回車,輸入import selenium 回車,如果沒有報錯,說明selenium安裝成功Firefox驅動需要從https://github.com/mozilla/geckodriver/releases網址下載geckodriver-v0.14.0-win64.zip的驅動包,下載後解壓geckodriver.exe檔案到任意目錄下,比如D:\在python指令碼中要加入下面的語句driver = webdriver.Firefox(executable_path= 'D:\geckodriver')備註:從selenium3.0版本開始,webdriver/firefox/webdriver.py程式檔案中的__init__.py檔案中,設定executable_path='geckodriver',而selenium2.0版本中executable_path='wires',所以使用selenium3.0編寫的自動化指令碼,使用Firefox瀏覽器測試時需要指明Firefox瀏覽器的驅動程式geckodriver.exe檔案所在路徑安裝Firefox瀏覽器最好使用預設路徑,否則可能無法找到firefox.exe檔案。