代码之家  ›  专栏  ›  技术社区  ›  EJoshuaS - Stand with Ukraine

在Firefox中运行Selenium测试会创建两个选项卡,并在“非活动”选项卡中运行

  •  0
  • EJoshuaS - Stand with Ukraine  · 技术社区  · 8 年前

    当我创建Firefox Web驱动程序的实例时,它成功地打开了Firefox。然而,它用两个选项卡打开它(一个“常规”Firefox选项卡和一个IE选项卡;IE选项卡处于活动状态,并且在测试期间保持活动状态,除非我手动切换到测试实际执行的选项卡)。

    enter image description here

    它将在Firefox选项卡(即非活动选项卡)中运行测试。

    var firefoxOptions = new FirefoxOptions()
    {
        Profile = new FirefoxProfile(),
        UseLegacyImplementation = false,
        BrowserExecutableLocation = @"C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"
    };
    
    firefoxDriver = new FirefoxDriver(firefoxOptions);
    
    firefoxDriver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 10);
    

    [TestCleanup]
    public void Cleanup()
    {
        if (firefoxDriver != null)
        {
            firefoxDriver.Close();
            firefoxDriver.Dispose();
        }
    }
    

    关闭该选项卡-IE选项卡和浏览器都保持打开状态。

    This question

    1 回复  |  直到 8 年前
        1
  •  1
  •   murali selenium    8 年前

    Firefox 44.0.1 opening two tabs , when running selenium webdriver code

    FirefoxProfile profile= new FirefoxProfile();
    profile.setPreference(“browser.startup.homepage”,”https://...");
    WebDriver driver = new FirefoxDriver(profile);
    

    只需使用 在firefox URL中,它将提供设置。