Python 3.x Selenium Firefox Webdriver在使用FirefoxProfile时调用Get失败

Python 3.x Selenium Firefox Webdriver在使用FirefoxProfile时调用Get失败,python-3.x,selenium,selenium-webdriver,selenium-firefoxdriver,geckodriver,Python 3.x,Selenium,Selenium Webdriver,Selenium Firefoxdriver,Geckodriver,selenium firefox Web驱动程序在调用“get”函数时崩溃。只有在我使用firefox\u配置文件时,当firefox\u profile=None时,才会发生此错误—一切正常。我使用的是Windows 10、Firefox 53.0.2 64位、Gecko驱动程序v0.16.1 win64、selenium 3.4.1和python 3.5.1 下面是我的代码 from selenium import webdriver import os downloadsDir = os

selenium firefox Web驱动程序在调用“get”函数时崩溃。只有在我使用firefox\u配置文件时,当firefox\u profile=None时,才会发生此错误—一切正常。我使用的是Windows 10、Firefox 53.0.2 64位、Gecko驱动程序v0.16.1 win64、selenium 3.4.1和python 3.5.1

下面是我的代码

from selenium import webdriver
import os

downloadsDir = os.path.join(os.getenv('HOMEPATH'),"Downloads")
geckoDriverPath = ""
for file in os.listdir(downloadsDir):
    if file.startswith("geckodriver") and not file.endswith(".log"):
        geckoDriverPath = os.path.join(downloadsDir, file)
        break

profilesDir = os.path.join(os.getenv('APPDATA') , "Mozilla", "Firefox", "Profiles")
ffProfileDir = ""
for profile in os.listdir(profilesDir):
    if profile.endswith(".default"):
        ffProfileDir = os.path.join(profilesDir, profile)
        break

firefoxDeskopProfile = webdriver.FirefoxProfile(profile_directory=ffProfileDir)            

#If I change the line below to "firefoxDesktopDriver = webdriver.Firefox(executable_path=geckoDriverPath)" then the code succeeds
firefoxDesktopDriver = webdriver.Firefox(firefox_profile=firefoxDeskopProfile, executable_path=geckoDriverPath)

firefoxDesktopDriver.get("https://www.google.com")
下面是我收到的错误

    C:\Users\username\Downloads>python test.py
Traceback (most recent call last):
  File "test.py", line 20, in <module>
    firefoxDesktopDriver.get("https://www.google.com")
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 264, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: No such content frame; perhaps the listener was not registered?
C:\Users\username\Downloads>python test.py
回溯(最近一次呼叫最后一次):
文件“test.py”,第20行,在
firefoxDesktopDriver.get(“https://www.google.com")
get中的文件“C:\Program Files(x86)\Python35-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第264行
self.execute(Command.GET,{'url':url})
文件“C:\Program Files(x86)\Python35-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第252行,在execute中
self.error\u handler.check\u响应(响应)
文件“C:\Program Files(x86)\Python35-32\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第194行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.NoSuchWindowException:消息:没有这样的内容框架;也许听众没有注册?

已经测试过几次了,实际上我在使用需要通过浏览器进行身份验证的网络时会出现此错误,但是当我在未经身份验证的情况下切换到网络时,它工作正常

已经测试过几次了,真的,当我使用一个需要通过浏览器进行身份验证的网络时,我会遇到这个错误,但是当我换成一个没有身份验证的网络时,它工作得很好