Monday, February 22, 2021

FireFox In C# Another


  //service.FirefoxBinaryPath = @"C:/Users/gg/AppData/Local/Mozilla Firefox/firefox.exe";     

                FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\gmr", "geckodriver.exe");

                FirefoxOptions options = new FirefoxOptions();

                options.AcceptInsecureCertificates = true;

                //Give the path of the Firefox Browser        

                service.FirefoxBinaryPath = @"C:/Users/gmr/AppData/Local/Mozilla Firefox/firefox.exe";                

                _driver = new OpenQA.Selenium.Firefox.FirefoxDriver(service, options);

Sunday, February 21, 2021

Edge Browser Open in C# Updated 


Install below nugget


using Microsoft.Edge.SeleniumTools;



  public void CreateDriver(string browser)

        {

            string baseUrl = GMR.GetSection().ServerUrl.ToString();


            if (browser?.Trim().ToUpper(CultureInfo.InvariantCulture) == "CHROME")

                _driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            else if (browser?.Trim().ToUpper(CultureInfo.InvariantCulture) == "IE")

            {

                InternetExplorerOptions options = new InternetExplorerOptions();

                options.RequireWindowFocus = true;

                //_driver = new InternetExplorerDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

                _driver = new InternetExplorerDriver(InternetExplorerDriverService.CreateDefaultService(), new InternetExplorerOptions(), TimeSpan.FromMinutes(3));



            }

            else if (browser?.Trim().ToUpper(CultureInfo.InvariantCulture) == "FIREFOX")

            {

                _driver = new FirefoxDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            }

            


else if (browser?.Trim().ToUpper(CultureInfo.InvariantCulture) == "EDGE")

            {

                var options = new Microsoft.Edge.SeleniumTools.EdgeOptions();

                options.UseChromium = true;

                _driver = new Microsoft.Edge.SeleniumTools.EdgeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);


            }



            _driver.Navigate().GoToUrl(new Uri(baseUrl));

            currentDriver = new NgWebDriver(_driver);

        }