2017-08-05 41 views
0

這裏是我的代碼:如何與特定的配置文件硒的Python geckodriver啓動Firefox

profile = webdriver.FirefoxProfile('C:\\Users\\Administrator\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\kvycjolb.Prdel') 
driver = webdriver.Firefox(profile) 

林沒有得到任何錯誤和Firefox的啓動,但它只是不與此配置文件加載:我試圖改變/去//等等,但沒有運氣。

這也不起作用:

from selenium import webdriver 
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile 
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 
binary = FirefoxBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe") 
profile = FirefoxProfile("C:\\Users\\Administrator\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\kvycjolb.Prdel") 
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path="C:\\aprog\\geckodriver.exe") 
driver.get('https://google.com') 

即時得到錯誤:

C:\aprog>testff 
Traceback (most recent call last): 
    File "C:\aprog\testff.py", line 7, in <module> 
    driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, e 
xecutable_path="C:\\aprog\\geckodriver.exe") 
    File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", 
line 152, in __init__ 
    keep_alive=True) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l 
ine 98, in __init__ 
    self.start_session(desired_capabilities, browser_profile) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l 
ine 188, in start_session 
    response = self.execute(Command.NEW_SESSION, parameters) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l 
ine 256, in execute 
    self.error_handler.check_response(response) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py" 
, line 194, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: Unable to find a matchin 
g set of capabilities 

回答

0

總是(至少對於Windows路徑)使用雙反斜線路徑:

profile = webdriver.FirefoxProfile('C:\\Users\\Administrator\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\kvycjolb.Prree') 

在你的代碼中,你使用反斜槓和正斜槓。

+0

我已經修復了代碼,但沒有解決問題。 – user3281831

0

要與特定的Firefox配置文件通過Selenium 3.4.3geckodriver v0.18.0Mozila Firefox 53.0Python 3.6啓動Mozilla Firefox瀏覽器,你需要創建一個單獨的Firefox Profile通過Firefox Profile Manager按照文檔here。我創建了名稱爲debanjanFirefox Profile。此配置文件存儲在「C:\ Users \ AtechM_03 \ AppData \ Roaming \ Mozilla \ Firefox \ Profiles」子目錄的名稱w8iy627a.debanjan。因此,儘管啓動WebDriver實例中,我們必須通過命名Firefox Profile的絕對路徑w8iy627a.debanjan如下:

from selenium import webdriver 
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile 
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 

binary = FirefoxBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe") 
profile = FirefoxProfile("C:\\Users\\AtechM_03\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\w8iy627a.debanjan") 
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe") 
driver.get('https://google.com') 

讓我知道如果這個回答你的問題。

+0

我使用python27,出現錯誤:無法找到匹配的功能集。 – user3281831

+0

您可以更新您的代碼和問題區域中的錯誤以供進一步分析嗎?謝謝 – DebanjanB

+0

更新了問題 – user3281831

相關問題