Webdriver啟用的火狐不帶插件,可以自已進行配置
先找到火狐的安裝路徑
C:\Program Files\Mozilla Firefox
步驟說明
在CMD中使用cd命令進入firefox.exe文件所在目錄(比如:C:\Program Files\Mozilla Firefox),
並輸入firefox.exe -ProfileManager -no-remote命令,然后按Enter鍵,
調出“Firefox – 選擇用戶配置文件”操作窗口
如果firefox.exe -ProfileManager -no-remote 執行彈出一個頁面說找不到路徑,解決方法:
在火狐的菜單“幫助”下,選擇“故障排除信息”,點擊后,在彈出的頁面中找到“配置文件夾 ”的
選項,點擊“打開文件夾”,可以獲取默認配置文件的全路徑。
進入mac的火狐路徑:/Applications/Firefox.app/Contents/MacOS
執行:firefox -profilemanager
新建profile
調出配置窗口,cmd下進入火狐的路徑,執行命令firefox.exe -ProfileManager -no-remote
選擇啟動時不詢問並使用選定的配置文件

可以創建配置文件
在創建的時候找到剛才做了配置的賬戶的路徑



找到剛才做了配置的賬戶的路徑替換到python文件里
C:\Users\Lenovo\AppData\Roaming\Mozilla\Firefox\Profiles\euhvixdt.default
#encoding=utf-8
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import unittest, time
class TestFailCaptureScreen(unittest.TestCase):
def setUp(self):
# 創建存儲自定義配置文件的路徑變量
#proPath = "C:\\Users\\wuxiaohua\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\tbbmxtkv.webdriver"
proPath = "C:\Users\Lenovo\AppData\Roaming\Mozilla\Firefox\Profiles\euhvixdt.default"
# 加載自定義配置文件到FirefoxProfile實例中,
# 等價profile = webdriver.FirefoxProfile(proPath)
profile = webdriver.firefox.firefox_profile.FirefoxProfile(proPath)
# 將添加了新配置文件的Firefox瀏覽器首頁設為搜狗主頁
profile.set_preference("browser.startup.homepage", "http://www.sogou.com")
# 設置開始頁面不是空白頁,0表示空白頁,
# 這一步必須做,否則設置的主頁不會生效
profile.set_preference("browser.startup.page", 1)
# 啟動帶自定義配置文件的Firefox瀏覽器
self.driver = webdriver.Firefox(executable_path="d:\\geckodriver", firefox_profile=profile)
def testSoGouSearch(self):
# 等待5秒,以便瀏覽器啟動完成
time.sleep(5)
try:
# 找到搜狗主頁搜索輸入框頁面元素
searchBox = self.driver.find_element_by_id("query")
# 在找到的搜索輸入框中輸入“光榮之路自動化測試”
searchBox.send_keys(u"光榮之路自動化測試")
# 找到搜索按鈕,並點擊
self.driver.find_element_by_id("stb").click()
time.sleep(10)
except NoSuchElementException, e:
print "修改帶自定義配置文件的瀏覽器主頁不成功!"
def tearDown(self):
# 退出Firefox瀏覽器
self.driver.quit()
if __name__ == '__main__':
unittest.main()
D:\test>python test.py
.
----------------------------------------------------------------------
Ran 1 test in 52.252s
OK
