栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

WebDriverException:消息:浏览器似乎已经退出,然后才能使用GeckoDriver Selenium和Python连接错误

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

WebDriverException:消息:浏览器似乎已经退出,然后才能使用GeckoDriver Selenium和Python连接错误

此错误消息…

WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

…暗示 GeckoDriver 无法启动/产生新的 WebBrowser,Firefox浏览器 会话。

您需要注意以下几点:

  • 要设置,
    FirefoxBinary
    您需要使用
    FirefoxOptions()
    和,而不是传递 geckodriver* 二进制文件的 绝对路径 必须传递所需的 firefox 二进制文件的 绝对路径*
  • 在使用 GeckoDriver v0.21.0时, 您必须强制使用 木偶, 因此请使其保持不变(默认情况下
    true
    )或将 木偶 设置为
    true
  • 您自己的代码(其中包含一些小的更改)将是:
        from selenium import webdriver    from selenium.webdriver.firefox.options import Options    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities    binary = r'C:Program FilesMozilla Firefoxfirefox.exe'    options = Options()    options.set_headless(headless=True)    options.binary = binary    cap = DesiredCapabilities().FIREFOX    cap["marionette"] = True #optional    driver = webdriver.Firefox(firefox_options=options, capabilities=cap, executable_path="C:\Utility\BrowserDrivers\geckodriver.exe")    driver.get("http://google.com/")    print ("Headless Firefox Initialized")    driver.quit()
  • 控制台输出:
    Headless Firefox Initialized


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/383373.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号