コード例 #1
0
        public static void Iniciar()
        {
            IWebDriver driver = null;

            try
            {
                // Código introdutório que acessa a main page do projeto Selenium e baixa os arquivos
                //necessários para começar o projeto.
                driver = GenericSelenium.IniciarWebsite("http://www.seleniumhq.org/", EDRIVERS.CHROME);
                GenericSelenium.GetElementIfPresentById(driver, "menu_download").Click();
                GenericSelenium.getCellByTableTitle(driver, "Language", 1, 3).Click();
                GenericSelenium.getCellByTableTitle(driver, "Browser", 1, 0).Click();
                // Navega para a pagina de download do Chrome Driver.
                GenericSelenium.getElementsContainsTextByTag(driver, "ChromeDriver", "a")[2].Click();
                GenericSelenium.getElementsContainsTextByTag(driver, "ChromeDriver", "a")[3].Click();
                GenericSelenium.getElementsContainsTextByTag(driver, "chromedriver_win32", "a")[0].Click();
                GenericSelenium.returnPages(driver, 6);
            }
            catch (Exception ex)
            {
                if (driver != null)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
コード例 #2
0
        public static void Iniciar()
        {
            IWebDriver driver = null;

            try
            {
                // Código introdutório que acessa a main page do projeto Selenium e baixa os arquivos necessários para começar o projeto.
                driver = GenericSelenium.IniciarWebsite("http://www.seleniumhq.org/", EDRIVERS.CHROME);
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));

                driver.FindElement(By.Id("menu_download")).Click();
                IWebElement downloadAPI = GenericSelenium.getCellByTableTitle(driver, "Language", 1, 3);
                IWebElement DriverPage  = GenericSelenium.getCellByTableTitle(driver, "Browser", 1, 0);
                downloadAPI.Click();

                // Navega para a pagina de download do Chrome Driver.
                DriverPage.Click();
                driver.FindElements(By.XPath("//div[@id='sites-canvas-main-content']//a[Contains(Text(),'ChromeDriver'))]"))[0].Click();
                driver.FindElements(By.XPath("//div[@id='sites-canvas-main-content']//a[Contains(Text(),'ChromeDriver'))]"))[0].Click();
                wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[Contains(Text(),'ChromeDriver_win32.zip')]"))).Click();
            }
            catch (Exception ex)
            {
                if (driver != null)
                {
                    Console.WriteLine(ex.Message);
                    //driver.Quit();
                }
            }
        }
コード例 #3
0
        public static void Iniciar()
        {
            IWebDriver driver = null;

            try
            {
                string dir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                string restaurante;
                string address  = "";
                string website  = "";
                string phone    = "";
                string openTime = "";
                string ComentariosPrincipais = "";
                string Nota            = "";
                bool   pulaRestaurante = false;

                // Read the file and display it line by line.
                System.IO.StreamReader file = new System.IO.StreamReader(@dir + "\\restaurantes.txt");
                StreamWriter           sw   = new StreamWriter(@dir + "\\restaurantesOutput.txt");
                driver = GenericSelenium.IniciarWebsite("https://www.google.com.br/maps/", EDRIVERS.CHROME);
                GenericSelenium.SaveCookieData(driver);

                while ((restaurante = file.ReadLine()) != null)
                {
                    driver.FindElement(By.Id("searchboxinput")).Clear();
                    driver.FindElement(By.Id("searchboxinput")).SendKeys(restaurante);
                    driver.FindElement(By.Id("searchbox-searchbutton")).Click();

                    System.Threading.Thread.Sleep(3000);

                    if (driver.FindElements(By.ClassName("section-result-text-content")).Count > 0)
                    {
                        if (GenericSelenium.getElementsContainsTextByTag(driver, restaurante, "span") != null)
                        {
                            GenericSelenium.getElementsContainsTextByTag(driver, restaurante, "span").FirstOrDefault().Click();
                        }
                        else
                        {
                            driver.FindElement(By.ClassName("section-result-text-content")).Click();
                        }
                    }


                    if (GenericSelenium.GetElementIfPresentByClassName(driver, "section-info-text") != null)
                    {
                        address = GenericSelenium.GetElementIfPresentByClassName(driver, "section-info-text").Text;
                    }
                    else
                    {
                        Console.WriteLine("Endereço não encontrado");
                        sw.WriteLine("Endereço não encontrado");
                        pulaRestaurante = true;
                    }

                    if (pulaRestaurante == false)
                    {
                        if (GenericSelenium.GetElementIfPresentByAttribute(driver, "data-attribution-url") != null)
                        {
                            website = GenericSelenium.GetElementIfPresentByAttribute(driver, "data-attribution-url").GetAttribute("data-attribution-url");
                        }

                        if (GenericSelenium.GetElementIfPresentByAttribute(driver, "data-href") != null)
                        {
                            phone = GenericSelenium.GetElementIfPresentByAttribute(driver, "data-href").GetAttribute("data-href");
                        }

                        if (GenericSelenium.GetElementIfPresentByClassName(driver, "section-info-hour-text") != null)
                        {
                            openTime = GenericSelenium.GetElementIfPresentByClassName(driver, "section-info-hour-text").Text;
                        }

                        ComentariosPrincipais = GenericSelenium.MontarComentarios(GenericSelenium.GetElementsOfGivenAttributeFromGivenClass(driver, "section-review-snippet-line", "jsinstance"));

                        if (GenericSelenium.GetElementIfPresentByClassName(driver, "section-star-display") != null)
                        {
                            Nota = GenericSelenium.GetElementIfPresentByClassName(driver, "section-star-display").Text;
                        }
                    }

                    pulaRestaurante = false;


                    if (website.Length > 100)
                    {
                        website = "";
                    }

                    int index = openTime.IndexOfAny("0123456789".ToCharArray());

                    if (index < 0)
                    {
                        index = 0;
                    }

                    Console.WriteLine("Carregando informações para : " + restaurante);

                    Console.WriteLine("Endereço: " + address);
                    Console.WriteLine("Website: " + website);
                    Console.WriteLine("Telefone: " + phone);
                    Console.WriteLine("Horarios: " + openTime.Substring(index));
                    Console.WriteLine("Comentarios Principais: " + ComentariosPrincipais);
                    Console.WriteLine("Nota dos usuarios: " + Nota);

                    Console.WriteLine("----------------------------------------");

                    sw.WriteLine("Carregando informações para : " + restaurante);

                    sw.WriteLine("Endereço: " + address);
                    sw.WriteLine("Website: " + website);
                    sw.WriteLine("Telefone: " + phone);
                    sw.WriteLine("Horarios: " + openTime.Substring(index));
                    sw.WriteLine("Comentarios Principais: " + ComentariosPrincipais);
                    sw.WriteLine("Nota dos usuarios: " + Nota);
                    sw.WriteLine("----------------------------------------");

                    address  = " ";
                    website  = " ";
                    phone    = " ";
                    openTime = " ";
                    ComentariosPrincipais = " ";
                    Nota = " ";
                }
                file.Close();
                sw.Close();
            }
            catch (Exception ex)
            {
                if (driver != null)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }