Example #1
0
        public void DebugLocalChrome()
        {
            try
            {
                //set configuration to be picked up and set Locator
                Config  = false;
                Browser = "Chrome";
                Env     = "Desktop";

                string path = TestUtility.GetAssemblyDirectory() + "//chromedriver.exe";
                Environment.SetEnvironmentVariable("webdriver.chrome.driver", path);

                ChromeOptions chrOpts = new ChromeOptions();
                chrOpts.AddArguments("test-type");
                chrOpts.AddArguments("--disable-extensions");
                // chrOpts.AddArgument("incognito");
                chrOpts.AddUserProfilePreference("download.prompt_for_download", ConfigurationManager.AppSettings["ShowBrowserDownloadPrompt"]);
                driver = new ChromeDriver(chrOpts);
                driver.Manage().Window.Maximize();
                driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings.Get("ElementPageLoad"))));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #2
0
        public void DebugBSChrome()
        {
            Browser           = "Chrome";
            Env               = "BS Desktop";
            Config            = false;
            configurationbool = false;
            DesiredCapabilities desiredCap = DesiredCapabilities.Chrome();
            ChromeOptions       chrOpts    = new ChromeOptions();

            chrOpts.AddArguments("test-type");
            chrOpts.AddArguments("--disable-extensions");
            //chrOpts.AddArgument("incognito");
            //desiredCap.SetCapability(ChromeOptions.Capability, chrOpts);    // updated
            desiredCap = (DesiredCapabilities)chrOpts.ToCapabilities();

            desiredCap.SetCapability("browserstack.user", browserstack_user);
            desiredCap.SetCapability("browserstack.key", browserstack_key);
            desiredCap.SetCapability("platform", "WINDOWS");
            desiredCap.SetCapability("os", "WINDOWS");
            desiredCap.SetCapability("os_version", "8");
            // desiredCap.SetCapability("build", Environment.GetEnvironmentVariable("BS_AUTOMATE_BUILD"));
            desiredCap.SetCapability("browserstack.debug", true);
            // string strTestName = TestContext.CurrentContext.Test.Name.ToString();
            desiredCap.SetCapability("project", Environment.GetEnvironmentVariable("BS_AUTOMATE_PROJECT"));
            desiredCap.SetCapability("build", Environment.GetEnvironmentVariable("BS_AUTOMATE_BUILD"));

            driver = new RemoteWebDriver(
                new Uri("http://hub-cloud.browserstack.com/wd/hub/"), desiredCap);

            SessionId = ((RemoteWebDriver)driver).SessionId.ToString();

            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings.Get("ElementPageLoad"))));
            driver.Manage().Window.Maximize();
        }
Example #3
0
 public FacebookAutomationTest()
 {
     OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
     options.AddArguments(new string[] { "--start-maximized", "--disable-notifications", "--incognito" });
     driver = new OpenQA.Selenium.Chrome.ChromeDriver(options);
     groups = new List <string>();
 }
        public override void RunCommand(object sender)
        {
            var engine         = (Core.Automation.Engine.AutomationEngineInstance)sender;
            var driverPath     = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Resources");
            var seleniumEngine = v_EngineType.ConvertToUserVariable(sender);
            var instanceName   = v_InstanceName.ConvertToUserVariable(sender);

            OpenQA.Selenium.DriverService driverService;
            OpenQA.Selenium.IWebDriver    webDriver;

            if (seleniumEngine == "Chrome")
            {
                OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();

                if (!string.IsNullOrEmpty(v_SeleniumOptions))
                {
                    var convertedOptions = v_SeleniumOptions.ConvertToUserVariable(sender);
                    options.AddArguments(convertedOptions);
                }

                driverService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService(driverPath);
                webDriver     = new OpenQA.Selenium.Chrome.ChromeDriver((OpenQA.Selenium.Chrome.ChromeDriverService)driverService, options);
            }
            else
            {
                driverService = OpenQA.Selenium.IE.InternetExplorerDriverService.CreateDefaultService(driverPath);
                webDriver     = new OpenQA.Selenium.IE.InternetExplorerDriver((OpenQA.Selenium.IE.InternetExplorerDriverService)driverService, new OpenQA.Selenium.IE.InternetExplorerOptions());
            }


            //add app instance
            engine.AddAppInstance(instanceName, webDriver);


            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(instanceName, webDriver);
            }

            //handle window type on startup - https://github.com/saucepleez/taskt/issues/22
            switch (v_BrowserWindowOption)
            {
            case "Maximize":
                webDriver.Manage().Window.Maximize();
                break;

            case "Normal":
            case "":
            default:
                break;
            }
        }
Example #5
0
        protected override async ValueTask <IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
        {
            var options = new OpenQA.Selenium.Chrome.ChromeOptions();

            if (UseHeadless)
            {
                options.AddArguments("headless");
            }
            var driverId = await _factory.OpenAsync(BrowserType, options, context.CancellationToken);

            Data[RpaWebConventions.DriverIdKey] = driverId;
            //this.SaveWorkflowContext = true;
            return(Done(driverId));
        }
Example #6
0
        public bool RecycleDriver(int recycleNavigateCount = 100)
        {
            if (this.Driver != null && this.NavigateCount < recycleNavigateCount)
            {
                return(false);
            }
            if (this.Driver != null)
            {
                this.Driver.Quit();
            }
            var options = new OpenQA.Selenium.Chrome.ChromeOptions();

            options.AddUserProfilePreference("profile.default_content_setting_values.images", 2);
            options.AddArguments("--start-maximized");
            this.Driver = new OpenQA.Selenium.Chrome.ChromeDriver(options);
            //this.RemoteWebDriver = new OpenQA.Selenium.Firefox.FirefoxDriver();
            NavigateCount = 0;
            return(true);
        }
Example #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
            options.AddArguments(@"user-data-dir=C:\Users\DAle\AppData\Local\Google\Chrome\User Data\Default");
            Browser = new OpenQA.Selenium.Chrome.ChromeDriver(options);
            Browser.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(300);
            Browser.Navigate().GoToUrl("https://evoplay.games/portfolio/high-striker/");
            System.Threading.Thread.Sleep(1000);
            Cursor.Position = new Point(925, 861);
            mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
            System.Threading.Thread.Sleep(100);
            mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
            System.Threading.Thread.Sleep(300);
            Cursor.Position = new Point(800, 620);
            mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
            System.Threading.Thread.Sleep(100);
            mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
            System.Threading.Thread.Sleep(2000);
            Browser.SwitchTo().Frame(0);
            Temp = Browser.FindElements(By.CssSelector("#app table tbody b")).ToList();
            //List<IWebElement> Results = Browser.FindElements(By.XPath("//*[@id='app']/div/div/div[5]/div/div[2]/table/tbody/tr[1]/td[1]/b")).ToList();
            //var i = 0;
            //double[] array = new double[19];
            int i = 0;

            foreach (var element in Temp)
            {
                dataGridView1[1, i].Value = GetValue(element);
                array[i] = Convert.ToDouble(dataGridView1[1, i].Value);
                GlobalTurns(Convert.ToDouble(dataGridView1[1, i].Value));
                //dataGridView1[0, i].Style.BackColor = Color.Red;
                i++;
            }
            Post();
            timer.Interval = 4900; // 5000 (5 сек)
            timer.Start();
            timer.Tick += button2_Click;
        }
Example #8
0
        public void DebugBSMobile(string strMobileDevice)
        {
            Config            = true;
            configurationbool = true;

            if (strMobileDevice == browsertype.android.ToString())
            {
                // ********************** sauce lab capabilities start **********************

                //Thread.Sleep(4000);
                //devicenameBS = ConfigurationManager.AppSettings.Get("androiddeviceNameBS");
                //this.deviceNameAndroid = ConfigurationManager.AppSettings.Get("androiddevice");
                //this.environment = ConfigurationManager.AppSettings.Get("environment");
                //DesiredCapabilities capability = DesiredCapabilities.Android();
                //capability.SetCapability("browserName", "Chrome");
                //capability.SetCapability("platformVersion", "6.1");
                //capability.SetCapability(MobileCapabilityType.BrowserName, MobileBrowserType.Chrome);
                //capability.SetCapability("username", "Sunil21318"); // supply sauce labs username
                //capability.SetCapability("accessKey", "d056215a-a397-414c-923f-e42e0be236b6");  // supply sauce labs account key
                //capability.SetCapability("deviceName", "Android Emulator");
                //capability.SetCapability("tunnel-identifier", Environment.GetEnvironmentVariable("TRAVIS_JOB_NUMBER"));
                //capability.SetCapability("build", Environment.GetEnvironmentVariable("TRAVIS_BUILD_NUMBER"));
                //capability.SetCapability("deviceReadyTimeout", TimeSpan.FromSeconds(120));
                //capability.SetCapability("androidDeviceReadyTimeout", TimeSpan.FromSeconds(120));
                //capability.SetCapability("avdLaunchTimeout", TimeSpan.FromSeconds(120));
                //capability.SetCapability("appWaitDuration", TimeSpan.FromSeconds(120));
                //capability.SetCapability("avdReadyTimeout", TimeSpan.FromSeconds(120));
                //capability.SetCapability("idleTimeout", 120);
                //driver = new RemoteWebDriver(new Uri("http://*****:*****@ondemand.saucelabs.com/wd/hub"), capability, TimeSpan.FromSeconds(120));
                //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(200));
                //driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(200));

                // ********************** sauce lab capabilities end **********************



                //  ********************** browser stack capabilities start **********************

                Browser = "Chrome";
                Env     = "Android";

                devicenameBS           = ConfigurationManager.AppSettings.Get("androiddeviceNameBS");
                this.deviceNameAndroid = ConfigurationManager.AppSettings.Get("androiddevice");
                this.environment       = ConfigurationManager.AppSettings.Get("environment");
                DesiredCapabilities capability = DesiredCapabilities.Android();
                ChromeOptions       chrOpts    = new ChromeOptions();
                chrOpts.AddArguments("test-type");
                chrOpts.AddArguments("--disable-extensions");
                chrOpts.AddArgument("incognito");
                chrOpts.AddArgument("no-sandbox");
                capability = (DesiredCapabilities)chrOpts.ToCapabilities();
                capability.SetCapability("browserName", "android");
                capability.SetCapability("browserstack.user", browserstack_user); // browser stack username
                capability.SetCapability("browserstack.key", browserstack_key);   // browser stack account key
                capability.SetCapability("deviceName", devicenameBS);
                capability.SetCapability("browserName", "chrome");
                capability.SetCapability("platform", MobilePlatform.Android);
                capability.SetCapability("browserstack.debug", true);
                capability.SetCapability("project", Environment.GetEnvironmentVariable("BS_AUTOMATE_PROJECT"));
                capability.SetCapability("build", Environment.GetEnvironmentVariable("BS_AUTOMATE_BUILD"));
                capability.SetCapability("browserstack.localIdentifier", Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL_IDENTIFIER"));
                capability.SetCapability("deviceReadyTimeout", TimeSpan.FromSeconds(200));
                capability.SetCapability("androidDeviceReadyTimeout", TimeSpan.FromSeconds(200));
                capability.SetCapability("avdLaunchTimeout", TimeSpan.FromSeconds(200));
                capability.SetCapability("appWaitDuration", TimeSpan.FromSeconds(200));
                capability.SetCapability("avdReadyTimeout", TimeSpan.FromSeconds(200));
                capability.SetCapability("idleTimeout", 300);
                driver = new RemoteWebDriver(new Uri(ConfigurationManager.AppSettings.Get("server")), capability, TimeSpan.FromSeconds(200));
                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(200));

                // ********************** browser stack capabilities end **********************
            }
            else if (strMobileDevice == browsertype.ios.ToString())
            {
                Browser = "Safari";
                Env     = "IOS";
                Thread.Sleep(4000);
                devicenameBS           = ConfigurationManager.AppSettings.Get("iosdeviceNameBS");
                this.deviceNameAndroid = ConfigurationManager.AppSettings.Get("iosdevice");
                this.environment       = ConfigurationManager.AppSettings.Get("environment");
                DesiredCapabilities desiredCap = DesiredCapabilities.IPhone();
                desiredCap.SetCapability("browserstack.user", browserstack_user);
                desiredCap.SetCapability("browserstack.key", browserstack_key);
                desiredCap.SetCapability("platform", "MAC");
                desiredCap.SetCapability("browserName", "iPhone");
                desiredCap.SetCapability("browserstack.debug", true);
                desiredCap.SetCapability("device", devicenameiphone);
                desiredCap.SetCapability("project", Environment.GetEnvironmentVariable("BS_AUTOMATE_PROJECT"));
                desiredCap.SetCapability("build", Environment.GetEnvironmentVariable("BS_AUTOMATE_BUILD"));
                desiredCap.SetCapability("browserstack.localIdentifier", Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL_IDENTIFIER"));
                desiredCap.SetCapability("newCommandTimeout", TimeSpan.FromSeconds(120));
                desiredCap.SetCapability("idleTimeout", TimeSpan.FromSeconds(120));
                driver = new RemoteWebDriver(new Uri(ConfigurationManager.AppSettings.Get("server")), desiredCap, TimeSpan.FromSeconds(120));
                // driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(200));
            }
        }
Example #9
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            //Variaveis
            IWebDriver driver = null;
            int        ToRow  = 0;
            int        ToCol  = 0;
            string     munc   = string.Empty;
            string     uf     = string.Empty;

            try
            {
                #region browser

                string url = @"https://e-gov.betha.com.br/e-nota/pesquisa_prestadores.faces";

                Browser browser = (Browser)Enum.Parse(typeof(Browser), ConfigurationManager.AppSettings["selenium_webdriver"].ToString());

                switch (browser)
                {
                case Browser.Chrome:
                {
                    //Create FireFox Service
                    OpenQA.Selenium.Chrome.ChromeDriverService chromeService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService();
                    chromeService.HideCommandPromptWindow = true;
                    chromeService.SuppressInitialDiagnosticInformation = true;
                    //Create FireFox Profile object
                    OpenQA.Selenium.Chrome.ChromeOptions chromeOptions = new OpenQA.Selenium.Chrome.ChromeOptions();
                    chromeOptions.AddArguments(string.Concat("--app=", url));
                    driver = new OpenQA.Selenium.Chrome.ChromeDriver(chromeService, chromeOptions);
                }
                break;

                case Browser.Edge:
                    driver = new OpenQA.Selenium.Edge.EdgeDriver();
                    break;

                case Browser.Firefox:
                {
                    //Create FireFox Service
                    OpenQA.Selenium.Firefox.FirefoxDriverService firefoxService = OpenQA.Selenium.Firefox.FirefoxDriverService.CreateDefaultService(string.Concat(Application.StartupPath, @"\Selenium\Firefox"));
                    firefoxService.HideCommandPromptWindow = true;
                    firefoxService.SuppressInitialDiagnosticInformation = true;
                    //Create FireFox Profile object
                    OpenQA.Selenium.Firefox.FirefoxOptions firefoxOptions = new OpenQA.Selenium.Firefox.FirefoxOptions();
                    driver = new OpenQA.Selenium.Firefox.FirefoxDriver(firefoxService, firefoxOptions);
                    driver.Navigate().GoToUrl(url);
                }
                break;

                case Browser.InternetExplorer:
                {
                    //Create FireFox Service
                    OpenQA.Selenium.IE.InternetExplorerDriverService InternetExplorerService = OpenQA.Selenium.IE.InternetExplorerDriverService.CreateDefaultService(string.Concat(Application.StartupPath, @"\Selenium\InternetExplorerDriver"));
                    InternetExplorerService.HideCommandPromptWindow = true;
                    InternetExplorerService.SuppressInitialDiagnosticInformation = true;
                    //Create FireFox Profile object
                    OpenQA.Selenium.IE.InternetExplorerOptions InternetExplorerOptions = new OpenQA.Selenium.IE.InternetExplorerOptions();
                    driver = new OpenQA.Selenium.IE.InternetExplorerDriver(InternetExplorerService, InternetExplorerOptions);
                    driver.Navigate().GoToUrl(url);
                }
                break;

                case Browser.Opera:
                {
                    //Create FireFox Service
                    OpenQA.Selenium.Opera.OperaDriverService OperaService = OpenQA.Selenium.Opera.OperaDriverService.CreateDefaultService(string.Concat(Application.StartupPath, @"\Selenium\Opera"));
                    OperaService.HideCommandPromptWindow = true;
                    OperaService.SuppressInitialDiagnosticInformation = true;
                    //Create FireFox Profile object
                    OpenQA.Selenium.Opera.OperaOptions OperaOptions = new OpenQA.Selenium.Opera.OperaOptions();
                    driver = new OpenQA.Selenium.Opera.OperaDriver(OperaService, OperaOptions);
                    driver.Navigate().GoToUrl(url);
                }
                break;

                default:
                    throw new NotSupportedException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Driver {0} não suportado", browser));
                }

                if (driver == null)
                {
                    throw new Exception("WebDriver do Selenium não definido nas configurações");
                }

                #endregion browser

                //Aguarda processamento da página 5min
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));

                //Arquivo
                FileInfo fileInfo = new FileInfo(string.Format(@"{0}\Prestadores.xls", Application.StartupPath));
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }

                using (ExcelPackage package = new ExcelPackage(fileInfo))
                {
                    try
                    {
                        #region UF

                        for (int i = 1; i < driver.FindElement(By.Id("mainForm:estado")).FindElements(By.TagName("option")).Count; i++)
                        {
                            try
                            {
                                if (i != 11)
                                {
                                    continue;
                                }

                                //Variaveis
                                ToRow = 1;
                                ToCol = 8; //Total de colunas
                                munc  = string.Empty;
                                uf    = string.Empty;

                                System.Threading.Thread.Sleep(1500);

                                //Seleciona UF
                                driver.FindElement(By.Id("mainForm:estado")).FindElements(By.TagName("option"))[i].Click();
                                uf = driver.FindElement(By.Id("mainForm:estado")).FindElements(By.TagName("option"))[i].Text;

                                System.Threading.Thread.Sleep(500);

                                //Worksheet
                                ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(uf.Trim());

                                #region Municipio

                                for (int j = 1; j < driver.FindElement(By.Id("mainForm:municipio")).FindElements(By.TagName("option")).Count; j++)
                                {
                                    try
                                    {
                                        //if(j != 61)
                                        //    continue;

                                        //Municipio
                                        driver.FindElement(By.Id("mainForm:municipio")).FindElements(By.TagName("option"))[j].Click();
                                        munc = driver.FindElement(By.Id("mainForm:municipio")).FindElements(By.TagName("option"))[j].Text;

                                        if (!driver.FindElement(By.Id("mainForm:master:messageSection:warn")).Displayed)
                                        {
                                            string html = driver.PageSource;
                                            if (!string.IsNullOrEmpty(html))
                                            {
                                                // Load From String
                                                var htmlDocument = new HtmlAgilityPack.HtmlDocument();
                                                htmlDocument.LoadHtml(html);

                                                bool blnPrestador = htmlDocument.GetElementbyId("mainForm:prestadores") == null ? false : true;

                                                do
                                                {
                                                    htmlDocument.LoadHtml(driver.PageSource);
                                                    blnPrestador = htmlDocument.GetElementbyId("mainForm:prestadores") == null ? false : true;
                                                } while (blnPrestador == false);

                                                var prestadores = htmlDocument.GetElementbyId("mainForm:prestadores");
                                                var tabela      = prestadores.SelectNodes("table");
                                                var linhas      = tabela.ElementAt(0).SelectNodes("tbody//tr");

                                                #region Add the headers row 1

                                                worksheet.Cells["A1"].Value = "Razão/Nome";
                                                worksheet.Cells["B1"].Value = "Logradouro";
                                                worksheet.Cells["C1"].Value = "Bairro";
                                                worksheet.Cells["D1"].Value = "Complemento";
                                                worksheet.Cells["E1"].Value = "CEP";
                                                worksheet.Cells["F1"].Value = "Email";
                                                worksheet.Cells["G1"].Value = "Telefone";
                                                worksheet.Cells["H1"].Value = "UF";
                                                worksheet.Cells["I1"].Value = "Municipio";

                                                //Format row header 1 style;
                                                using (var range = worksheet.Cells["A1:I1"])
                                                {
                                                    range.Style.Font.Bold        = true;
                                                    range.Style.Fill.PatternType = ExcelFillStyle.Solid;
                                                    range.Style.Font.Color.SetColor(Color.Black);
                                                    range.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(198, 198, 198));
                                                    range.Style.VerticalAlignment   = ExcelVerticalAlignment.Center;
                                                    range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                                                }

                                                #endregion Add the headers row 1

                                                #region Add some items in the cells

                                                foreach (HtmlNode linha in linhas)
                                                {
                                                    ToRow++;

                                                    foreach (HtmlNode campos in linha.SelectNodes("td"))
                                                    {
                                                        if (linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(0).HasChildNodes)
                                                        {
                                                            worksheet.Cells[ToRow, 1].Value = ConverterCaracteresEspeciais(linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(0).FirstChild.InnerText);
                                                            worksheet.Cells[ToRow, 2].Value = linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(3).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                            worksheet.Cells[ToRow, 3].Value = linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(5).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                            worksheet.Cells[ToRow, 4].Value = linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(7).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                            worksheet.Cells[ToRow, 5].Value = linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(9).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                        }

                                                        if (linha.SelectNodes("td").ElementAt(1).HasChildNodes)
                                                        {
                                                            worksheet.Cells[ToRow, 6].Value = linha.SelectNodes("td").ElementAt(1).ChildNodes.ElementAt(0).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                            worksheet.Cells[ToRow, 7].Value = linha.SelectNodes("td").ElementAt(1).ChildNodes.ElementAt(2).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                        }

                                                        string[] arr = uf.ToString().Split('-');

                                                        worksheet.Cells[ToRow, 8].Value = arr[0].Trim();
                                                        worksheet.Cells[ToRow, 9].Value = munc;
                                                    }
                                                }

                                                #endregion Add some items in the cells
                                            }
                                        }
                                    }
                                    catch (Exception ex) { throw; }
                                }

                                #endregion Municipio

                                #region Format type cells
                                //Format type cells
                                for (int fc = 0; fc < ToRow; fc++)
                                {
                                    //Row
                                    if (fc <= 1)
                                    {
                                        continue;
                                    }

                                    //Campos
                                    worksheet.Cells[fc, 1].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 2].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 3].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 4].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 5].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 6].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 7].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 8].Style.Numberformat.Format = "@";
                                }

                                #endregion Format type cells

                                if (ToRow == 1)
                                {
                                    worksheet = null;
                                    continue;
                                }

                                //Format the values
                                using (var range = worksheet.Cells[2, 1, ToRow, ToCol])
                                {
                                    range.Style.VerticalAlignment   = ExcelVerticalAlignment.Center;
                                    range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                                }

                                //Create an autofilter for the range
                                worksheet.Cells[1, 1, ToRow, ToCol].AutoFilter = true;

                                //Excel line freeze
                                worksheet.View.FreezePanes(2, 1);

                                //Autofit columns for all cells
                                worksheet.Cells.AutoFitColumns(0);

                                //// Change the sheet view to show it in page layout mode
                                //worksheet.View.PageLayoutView = false;
                            }
                            catch { }
                        }

                        #endregion UF
                    }
                    catch (Exception ex)
                    {
                        if (driver != null)
                        {
                            driver.Dispose();
                        }
                    }
                    finally
                    {
                        // set some document properties
                        package.Workbook.Properties.Title = "Prestadore e-Notas";

                        // save our new workbook and we are done!
                        package.Save();
                    }
                }
            }
            catch (Exception)
            {
                if (driver != null)
                {
                    driver.Dispose();
                }
            }
            finally
            {
                if (driver != null)
                {
                    driver.Dispose();
                }
            }
        }