Selenium壁虎驱动程序执行findElement的速度是chromedriver(.Net)的10倍



很抱歉没有找到类似的问题,也许有人可以帮忙。

由于额外的要求,我们不仅要用Chrome测试我们的项目,还要用Firefox测试。当我们简单地将测试上下文更改为Firefox时,findElement的所有调用所花费的时间是Chrome的10倍。所有的测试都被彻底破坏了。我们试着使用不同的测试机器,但结果是一样的。该项目在Core上。网对于测试,我们使用MSTestV2、Firefox63(64位(和Geckodriver0.22(64位的(。

非常感谢您的帮助。

通过参考前面的答案,我的问题通过下面的代码得到了解决。

string geckoDriverDirectory = "Path of geckodriver.exe"
FirefoxDriverService geckoService = 
FirefoxDriverService.CreateDefaultService(geckoDriverDirectory);
geckoService.Host = "::1";
var firefoxOptions = new FirefoxOptions();
firefoxOptions.AcceptInsecureCertificates = true;
Driver = new FirefoxDriver(geckoService, firefoxOptions);

是的。你肯定遇到了性能问题。NET核心。在Chrome、IE或Edge上不会发生这种情况,因为每种浏览器的驱动程序可执行文件(与geckodriver不同(都侦听IPv4和IPv6环回地址。如果您要指定"::1"作为geckodriver的主机。NET,问题就会消失。

请参阅https://github.com/SeleniumHQ/selenium/issues/6597

一个完整的。Firefox的Net Core网络驱动程序2020年7月14日:

// .Net Core workaround #1: Slow Firefox webdriver
string projectFolder = Directory.GetParent(Directory.GetCurrentDirectory()).FullName;
string geckoDriverDirectory = projectFolder + "\netcoreapp3.1\";
FirefoxDriverService geckoService = 
FirefoxDriverService.CreateDefaultService(geckoDriverDirectory);
geckoService.Host = "::1";
var ffOptions = new FirefoxOptions();
ffOptions.BrowserExecutableLocation = @"C:Program FilesMozilla FirefoxFirefox.exe"; 
ffOptions.AcceptInsecureCertificates = true;
// This profile will by-pass *ALL* credentials. Note that Chrome uses Internet Explorer settings, so it does not need this.
// You must pre-setup the profile, by launching Firefox and doing phone authentication
// The profile's location is: C:Users<windows logon>AppDataLocalMozillaFirefoxProfiles
// Without this, if your AUT uses SSO, you will always get prompted for the PIN or Two factor authentication
FirefoxProfile profile = new FirefoxProfileManager().GetProfile("Selenium");
ffOptions.Profile = profile;
// DotNet Core workaround #2- Code page
// https://stackoverflow.com/questions/56802715/firefoxwebdriver-no-data-is-available-for-encoding-437
// https://stackoverflow.com/questions/50858209/system-notsupportedexception-no-data-is-available-for-encoding-1252
CodePagesEncodingProvider.Instance.GetEncoding(437);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
_driver = new FirefoxDriver(geckoService, ffOptions);

如果有人在Javascript中尝试gary.zhang的答案,它看起来是这样的:

let driver = new Builder()
.forBrowser('firefox')
.setFirefoxService(new firefox.ServiceBuilder('path_to_driver', host='::1'))
.setFirefoxOptions(new firefox.Options().headless())
.build();

我花了一些时间来研究如何转换语法。

最新更新