Skip to content

Instantly share code, notes, and snippets.

@rahulrathore44
Created December 31, 2020 00:41
Show Gist options
  • Save rahulrathore44/d443facdd4c1be26c8c81ded692bda1b to your computer and use it in GitHub Desktop.
Save rahulrathore44/d443facdd4c1be26c8c81ded692bda1b to your computer and use it in GitHub Desktop.
Ope Existing Firefox browser in Selenium
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
namespace SeleniumTest
{
[TestClass]
public class UnitTest1
{
IWebDriver driver;
[TestMethod]
public void TestMethod1()
{
string gec_path = @"C:\Users\rathr1\Downloads\geckodriver-v0.28.0-win64";
string firefox = @"C:\Data\testfirefox\firefox.exe";
string profile_dir = @"C:\Data\testfirefox\prof\";
FirefoxOptions options = new FirefoxOptions();
options.AddArguments("--disable-extensions");
options.AddArgument("--ignore-certificate-errors");
options.Profile = new FirefoxProfile(profile_dir); // This should be the non-empty firefox profile directory.
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(gec_path, "geckodriver.exe");
service.FirefoxBinaryPath = firefox;
service.SuppressInitialDiagnosticInformation = true;
service.HideCommandPromptWindow = true;
driver = new FirefoxDriver(service, options, TimeSpan.FromMinutes(1));
driver.Manage().Window.Maximize();
driver.Navigate().Refresh();
}
[TestCleanup]
public void ShutDown()
{
driver?.Quit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment