gpt4 book ai didi

c# - IE 11 - webdriver.Quit() 不起作用

转载 作者:行者123 更新时间:2023-11-30 12:58:45 24 4
gpt4 key购买 nike

我是 Selenium 的新手,似乎遇到了第一个障碍。虽然我可以在 Firefox 中非常愉快地关闭浏览器窗口,但在 IE 中却无法正常工作。

请参阅下面的示例测试,每次运行时都会留下一个打开的 IE 窗口:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;

namespace TestingTesting123
{
[TestClass]
public class About
{
IWebDriver _ieDriver;
IWebDriver _ffDriver;

[TestInitialize]
public void Startup()
{
_ffDriver = new FirefoxDriver(); // Closes
_ieDriver = new InternetExplorerDriver(); // Doesn't
}

[TestMethod]
public void Go_to_bbc()
{
_ffDriver.Url = "http://news.bbc.co.uk";
_ieDriver.Url = "http://news.bbc.co.uk";
}

[TestCleanup]
public void Cleanup()
{
_ffDriver.Quit();
_ieDriver.Quit();
}
}
}

报告了类似的问题here对于 Java - 我似乎有同样的问题,但 C#。

我在 Windows 8.1 上使用 IE 11。我可以通过这样做来解决这个问题:

using System.Diagnostics;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;

namespace TestingTesting123Workaround
{
[TestClass]
public class About
{
IWebDriver _ieDriver;
IWebDriver _ffDriver;
int[] _startupIEProcessIds;

[TestInitialize]
public void Startup()
{
_startupIEProcessIds = Process.GetProcessesByName("iexplore")
.Select(x => x.Id).ToArray();

_ffDriver = new FirefoxDriver();
_ieDriver = new InternetExplorerDriver();
}

[TestMethod]
public void Go_to_bbc()
{
_ffDriver.Url = "http://news.bbc.co.uk";
_ieDriver.Url = "http://news.bbc.co.uk";
}

[TestCleanup]
public void Cleanup()
{
_ffDriver.Quit();
_ieDriver.Quit();

foreach (var ieDriver in Process.GetProcessesByName("IEDriverServer"))
ieDriver.Kill();
foreach (var ie in Process.GetProcessesByName("iexplore")
.Where(x => !_startupIEProcessIds.Contains(x.Id)))
ie.Kill(); // Typing that was oddly therapeutic
}
}
}

但是,这似乎非常繁琐,不是最佳实践。有什么想法吗?

最佳答案

您可能想试一试,因为退出/关闭应该有效。 可能是 IE 当前有一个错误,稍后会修复,但与此同时这可能会有所帮助。我过去在 chrome 驱动程序和 firefox 上遇到过类似的问题。

Internet Explorer 11 does not close after Selenium Test

关于c# - IE 11 - webdriver.Quit() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28697568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com