2017-08-05 30 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

相关问题