Selenium geckodriver executes findElement 10 times slower than chromedriver (.Net)

后端 未结 3 418
南笙
南笙 2021-01-06 11:00

Sorry didn\'t find a similar question and maybe somebody can help.

Due to additional requirements we have to test our project not only with Chrome but with Firefox

相关标签:
3条回答
  • 2021-01-06 11:16

    A complete .Net Core webdriver for Firefox 7/14/2020:

    // .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 Files\Mozilla Firefox\Firefox.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>\AppData\Local\Mozilla\Firefox\Profiles
    // 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);
    
    0 讨论(0)
  • 2021-01-06 11:25

    Yep. You’re definitely hitting the performance issue that is part of .NET Core. It doesn’t happen on Chrome, IE, or Edge, because the driver executables for each of those browsers (unlike geckodriver) listen on both the IPv4 and IPv6 loopback addresses. If you were to specify “::1” as the host for geckodriver with .NET, the problem would disappear.

    Refer to https://github.com/SeleniumHQ/selenium/issues/6597

    0 讨论(0)
  • 2021-01-06 11:32

    By referring to the previous answer, my issue was solved by below code.

    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);
    
    0 讨论(0)
提交回复
热议问题