【问题标题】:Selenium Firefox Webdriver Fails with call to Get when using FirefoxProfileSelenium Firefox Webdriver 在使用 FirefoxProfile 时调用 Get 失败
【发布时间】:2017-10-09 18:04:03
【问题描述】:

在调用“get”函数期间,selenium firefox webdriver 对我来说崩溃了。该错误仅在我使用 firefox_profile 时发生,当 firefox_profile=None 一切正常时。我正在使用 Windows 10、Firefox 53.0.2 64 位、Gecko Driver 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?

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver selenium-firefoxdriver geckodriver


    【解决方案1】:

    已经测试了好几次,真的,当我使用需要通过浏览器进行身份验证的网络时,我会收到此错误,但是当我更改为没有身份验证的网络时,它工作正常

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-07
      • 2015-04-29
      • 2014-10-07
      相关资源
      最近更新 更多