【问题标题】:Firefox via GeckoDriver throws exception on .Quit() in Selenium 3.0.1Firefox 通过 GeckoDriver 在 Selenium 3.0.1 中的 .Quit() 上引发异常
【发布时间】:2017-04-28 01:19:56
【问题描述】:

上下文:Firefox 50.0.2 64 位、C#、Visual Studio 2015、Windows Server 2012 R2、Azure、ClearScript.V8.5.4.7、Selenium.Mozilla.Firefox.Webdriver.0.6.0.1、Selenium.WebDriver.GeckoDriver。 Win64.0.11.1

我正在使用 ClearScript 包装 Selenium 对象以在 JavaScript 中使用,即

    static JScriptEngine JSengine = null;
    ...
    JSengine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging | WindowsScriptEngineFlags.EnableJITDebugging);
    ...
    JSengine.AddHostType("CSFirefoxDriver", typeof(FirefoxDriver));
    JSengine.AddHostType("CSFirefoxOptions", typeof(FirefoxOptions));
    JSengine.AddHostType("CSFirefoxDriverService", typeof(FirefoxDriverService));

我使用以下 JS 实例化 Firefox

var driverService = CSFirefoxDriverService.CreateDefaultService();
driverService.FirefoxBinaryPath = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";
driverService.HideCommandPromptWindow = true;
driverService.SuppressInitialDiagnosticInformation = true;
var options = new CSFirefoxOptions();
driver = new CSFirefoxDriver(driverService, options, CSTimeSpan.FromSeconds(30));

匹配的退出/处置代码是

try {
  driver.Quit();
} catch (E) {
  T.Error().Send("driver.Quit() failed.");
}

try {
  driver.Dispose();
} catch (E) {
  T.Error().Send("driver.Dispose() failed.");
}

(T 是一个日志对象)

当执行 .Quit() 方法调用时,我得到以下对话框。

如果我将 .Quit() 注释掉,那么我在 .Dispose() 上会得到相同的结果。

其他论坛建议在 Firefox 的首选项中关闭硬件加速。这根本没有任何区别。

geckodriver 论坛上也有一个问题,声称对此进行了某种修复。现在肯定没有解决。

Windows 事件日志在这里并不是特别有用,即

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Name="Application Popup" Guid="{47BFA2B7-BD54-4FAC-B70B-29021084CA8F}" /> 
        <EventID>26</EventID> 
        <Version>0</Version> 
        <Level>4</Level> 
        <Task>0</Task> 
        <Opcode>0</Opcode> 
        <Keywords>0x8000000000000000</Keywords> 
        <TimeCreated SystemTime="2016-12-13T03:16:28.936810900Z" /> 
        <EventRecordID>1227958</EventRecordID> 
        <Correlation /> 
        <Execution ProcessID="5856" ThreadID="11580" /> 
        <Channel>System</Channel> 
        <Computer>VM1-SQLWEB-W12</Computer> 
        <Security UserID="S-1-5-18" /> 
    </System>
    <EventData>
        <Data Name="Caption">firefox.exe - Application Error</Data> 
        <Data Name="Message">The exception Breakpoint A breakpoint has been reached. (0x80000003) occurred in the application at location 0x880f00ef. Click on OK to terminate the program Click on CANCEL to debug the program</Data> 
    </EventData>
</Event>

我从这里去哪里?在找到修复程序之前,我可以回退到 PhantomJS。

【问题讨论】:

标签: c# azure selenium firefox geckodriver


【解决方案1】:

我有同样的问题,我发现有人发布了它here。现在你可以降级到 Firefox 48.0.2 直到它被修复。

【讨论】:

    【解决方案2】:

    问题仅出现在 Windows 8.1 上(我检查了 win7 和 wind10,它工作正常)。所以你应该升级你的操作系统或降级浏览器。

    【讨论】:

    • 降级浏览器是唯一可行的途径。 Azure 服务器正在运行 Server 2012 R2,我无法升级操作系统/
    【解决方案3】:

    如果使用 driver.quit(),此问题与 webdriver.gecko.driver 有关 我在 selenium-java-3.0.1、FF v 50.1.0、Eclipse Kepler、JDK1.8 遇到了同样的问题

    解决方案:使用 driver.close()

    【讨论】:

    • driver.close() 与 driver.quit() 不同
    • 嘿科里。您绝对正确, driver.close() 和 driver.quit() 不一样。 driver.quit() 关闭所有浏览器实例,其中 driver.close() 将关闭当前浏览器会话。但是由于当前 gecko 驱动程序的限制,如果你想在 firefox 中运行脚本,那么 driver.close() 将毫无例外地工作。
    • 几乎正确。 quit() 杀死整个 webdriver,而 close() 只关闭当前选项卡/窗口。 quit() 调用 close() 作为驱动程序清理的一部分。这是一个微妙但重要的区别。
    【解决方案4】:

    使用这个。杀死所有firefox的进程和异常窗口的进程(网上加入2个解决方案):

    string sProcessName = "firefox";
    
                if (driver.Capabilities.BrowserName == sProcessName)
                {
                    // Special fix for firefox because of issue https://github.com/mozilla/geckodriver/issues/173
                    // Kills all firefox processes
    
                    Process[] oProccesses = null;
                    bool bFound = true;
    
                    while (bFound == true)
                    {
                        bFound = false;
                        oProccesses = System.Diagnostics.Process.GetProcessesByName(sProcessName);
    
                        foreach (Process oCurrentProcess in oProccesses)
                        {
                            bFound = true;
                            //oCurrentProcess.Kill();
    
    
                            int waitTimeSecs = 2;
    
                            bool cleanExit = oCurrentProcess.WaitForExit(waitTimeSecs * 1000);
                            if (!oCurrentProcess.HasExited)
                            {
                                oCurrentProcess.CloseMainWindow();
                                System.Threading.Thread.Sleep(2000);
                            }
    
                            if (!oCurrentProcess.HasExited)
                            {
                                oCurrentProcess.Kill();
                                oCurrentProcess.WaitForExit();
                                // if an exception window has popped up, that needs to be killed too
    
                                foreach (var process in Process.GetProcessesByName("firefox"))
                                {
                                    process.CloseMainWindow();
                                    System.Threading.Thread.Sleep(2000);
                                    if (!process.HasExited)
                                        process.Kill();
                                }
                            }
    
    
                        }
                    }
                    driver.Quit();
                }
    

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 2021-05-10
      • 2021-04-15
      • 1970-01-01
      • 2019-06-28
      • 2017-06-18
      • 2020-11-03
      • 2017-08-03
      • 2019-03-13
      相关资源
      最近更新 更多