Created
December 31, 2020 00:41
-
-
Save rahulrathore44/d443facdd4c1be26c8c81ded692bda1b to your computer and use it in GitHub Desktop.
Ope Existing Firefox browser in Selenium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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