コード例 #1
0
ファイル: Program.cs プロジェクト: vladisvit/TestSelenium
        static void Main(string[] args)
        {
            int expectedResult;

            if (args.Length != 3 || string.IsNullOrEmpty(args[0]) || string.IsNullOrEmpty(args[1]) || !int.TryParse(args[2], out expectedResult))
            {
                Console.WriteLine("Please use the tools with next agruments <0- value of the dropdown country> <1- value of the droupdown language> <2 value of the expectedResult (integer)>");
                return;
            }

            var country  = args[0];
            var language = args[1];

            Console.WriteLine("Start the Chrome browser");
            var        directoryInfo      = Directory.GetParent(Environment.CurrentDirectory);
            var        parent             = directoryInfo.Parent.Parent.FullName;
            var        pathToChromeDriver = Path.Combine(parent, "chrome");
            IWebDriver driver             = new ChromeDriver(pathToChromeDriver);

            SetUpOptions(driver);

            SetUpElement(driver, "#country-element", By.CssSelector($"span[data-value='{country}']"));
            SetUpElement(driver, "#language", By.XPath($"//label[text()[contains(.,'{language}')]]/span"));

            driver.ExecuteJavaScript("window.scrollTo(0, document.body.scrollHeight-100)");
            var buttonAllJob = driver.FindElement(By.XPath("//a[contains(@class, 'content-loader-button load-more-button')]"));

            if (buttonAllJob.Displayed)
            {
                buttonAllJob.Click();
            }

            // this code does not work driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
            Thread.Sleep(5000); // only way to wait loading all job elements

            var wait             = new WebDriverWait(driver, TimeSpan.FromSeconds(1));
            var resultFindedJobs = wait.Until(e => e.FindElements(By.XPath("//div[@class='container']//div[contains(@class, 'vacancies-blocks-col')]")));

            Console.WriteLine($"TotalJobs:{resultFindedJobs.Count}");

            if (resultFindedJobs.Count == expectedResult)
            {
                Console.WriteLine("Find all job elements");
            }
            else
            {
                Console.WriteLine("Wrong result!!!");
            }

            driver.Quit();
        }
コード例 #2
0
        public void JSExecutor()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Url = "https://abrakh.com/";
            driver.Manage().Window.Maximize();
            // 1 way
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;

            js.ExecuteScript("window.scrollBy(0, 1000)");
            //driver.FindElement(By.XPath("//body")).SendKeys(Keys.PageDown);
            var header = driver.FindElement(By.XPath("//h1"));

            js.ExecuteScript("arguments[0].setAttribute('style', 'background: yellow; border: 3px solid red;');", header);
            // 2 way
            driver.ExecuteJavaScript("window.scrollBy(0, 1000)");
        }
コード例 #3
0
ファイル: Browser.cs プロジェクト: tazik047/seleniumParser
        public Browser(AppConstants appConstants)
        {
            _appConstants = appConstants;
            var option = new ChromeOptions();

            option.AddArgument(string.Format("load-extension={0}\\AdBlock", AppDomain.CurrentDomain.BaseDirectory));
            _chrome = new ChromeDriver(option);
            _chrome.Manage().Window.Maximize();
            if (_chrome.WindowHandles.Count > 1)
            {
                var newTabInstance = _chrome.WindowHandles[_chrome.WindowHandles.Count - 1];
                // switch our WebDriver to the new tab's window handle
                _chrome.SwitchTo().Window(newTabInstance);
                var t = _chrome.ExecuteJavaScript <object>("window.close();", null);
                _chrome.SwitchTo().Window(_chrome.WindowHandles[0]);
            }
        }
コード例 #4
0
        public string GetVoterId()
        {
            var voterId = _driver.ExecuteJavaScript <string>("return $.cookie('voter_id')");

            return(voterId);
        }
コード例 #5
0
        public void AutomacaoDeComissao()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder  = new Actions(driver);
                //builder.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }
            Login login = new Login();

            System.Threading.Thread.Sleep(6000);

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            #region Automação de comissão
            //Seleciona Automação de comissão
            System.Threading.Thread.Sleep(8000);//Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".icon-receipt:nth-child(2)")).Click();

            //Clica na cia "Bradesco"
            //            driver.ExecuteJavaScript("window.scroll(0,1000)");//Scroll na página
            System.Threading.Thread.Sleep(10000);//Aguardando a pagina carregar
            try
            {
                driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[3]/div[1]/div[2]/div/div[19]")).Click();
            }
            catch
            {
                driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[3]/div[1]/div[2]/div/div[19]/div/div[2]")).Click();
            }
            //Informa corretora
            driver.FindElement(By.Id("comboundefined")).Click();
            driver.FindElement(By.Id("comboundefined")).SendKeys("matriz");
            driver.FindElement(By.Id("comboundefined")).SendKeys(Keys.Enter);


            //Desmarcar
            System.Threading.Thread.Sleep(20000);//Aguardando a pagina carregar
            //driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div > div:nth-child(4) > div > div.clearfix.card-header.bg-card-teal > div > spam:nth-child(2)")).Click();
            //driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[2]/div/div[2]/div[2]/div/div/div[1]/table/tbody/tr/td[1]/vs-editavel3/div/label/input")).Click();
            //Marcar somente um
            driver.ExecuteJavaScript("window.scroll(0,1000)");

            string semArquivos = driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[3]/div/div[2]/div/h5")).Text;

            System.Threading.Thread.Sleep(5000);

            try
            {
                string qtdArquivosBaixados = driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[4]/div/div[1]/h2")).Text;
                int    qtdArqBaixados      = MetodosNavega.DevolveNumeroDeUmTexto(qtdArquivosBaixados);

                if (qtdArqBaixados >= 1)
                {
                    if (qtdArqBaixados == 1)
                    {
                        driver.FindElement(By.CssSelector(".ng-scope:nth-child(1) > td .check")).Click();
                        driver.FindElement(By.CssSelector(".ng-scope:nth-child(1) > td .check")).Click();
                    }
                    else
                    {
                        try
                        {
                            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[4]/div/div[1]/div/spam[2]")).Click();
                        }
                        catch
                        {
                            for (int i = 1; i <= qtdArqBaixados; i++)
                            {
                                driver.FindElement(By.CssSelector(".ng-scope:nth-child(" + i + ") > td .check")).Click();
                            }
                        }

                        driver.FindElement(By.CssSelector(".ng-scope:nth-child(1) > td .check")).Click();
                    }

                    System.Threading.Thread.Sleep(5000);
                    //Continuar
                    driver.FindElement(By.CssSelector(".btn-md")).Click();
                    System.Threading.Thread.Sleep(5000);
                    //Grava
                    System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
                    System.Threading.Thread.Sleep(5000);

                    //ESC para fechar a tela de dados da importação
                    System.Threading.Thread.Sleep(5000);
                    Actions action = new Actions(driver);
                    action.SendKeys(OpenQA.Selenium.Keys.Escape).Perform();
                    System.Threading.Thread.Sleep(5000);
                    driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[5]/div/div/button")).Click();
                    System.Threading.Thread.Sleep(5000);

                    if (driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[2]/div[2]/div/div[1]/h2")).Displayed)
                    {
                        //Definindo a categoria e conta para envio ao cashflow
                        driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[5]/div/div/button[2]")).Click();
                        System.Threading.Thread.Sleep(6000);


                        IWebElement categoria = driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[2]/div/div/div[4]/vs-editavel3/div/input"));
                        IWebElement conta     = driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[2]/div/div/div[5]/vs-editavel3/div/input"));

                        {
                            Actions actionProvider = new Actions(driver);
                            actionProvider.Click(categoria).Build().Perform();
                            actionProvider.Click(categoria).Build().Perform();
                            actionProvider.SendKeys(categoria, "COMISSÕES RECEBIDAS");
                            actionProvider.Click(categoria).Build().Perform();
                            driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[2]/div/div/div[4]/vs-editavel3/div/ul/li/a")).Click();
                        }

                        {
                            Actions actionProvider2 = new Actions(driver);
                            // Perform click-and-hold action on the element
                            actionProvider2.Click(conta).Build().Perform();
                            actionProvider2.Click(conta).Build().Perform();
                            actionProvider2.SendKeys(conta, "CONTA BB").Build().Perform();
                            driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[2]/div/div/div[5]/vs-editavel3/div/ul/li/a")).Click();
                        }

                        //Clicando no Gravar informações.
                        driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[3]/div/button[3]")).Click();
                    }
                }
            }
            catch
            {
                IWebElement graverInformacaoes = driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[3]/div/button[3]"));
                Actions     actionsProvider3   = new Actions(driver);
                actionsProvider3.Click(graverInformacaoes).Build().Perform();
            }

            #endregion

            System.Threading.Thread.Sleep(5000); //Aguardando a pagina carregar
                                                 //Fecha o navegador
            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #6
0
        public void CadastroDePJ()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }

            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys("francisco");
            driver.FindElement(By.Id("senha")).SendKeys("F123456");
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            System.Threading.Thread.Sleep(2000); //Aguardando a pagina carregar
            driver.FindElement(By.Id("botaoMenu")).Click();
            System.Threading.Thread.Sleep(1000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("div:nth-child(3) > ul > li:nth-child(2) > a > span")).Click();
            System.Threading.Thread.Sleep(1000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div > div > form > div.paddingCard.col-lg-7.col-md-12.col-sm-12.col-xs-12 > div > div.clearfix.card-header.bg-card-teal > button")).Click();
            //Informa Nome
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_nome")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_nome")).SendKeys("MONSTROS SA");
            //Informa Tipo de Pessoa
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_tipo_pessoa")).Click();
            driver.FindElement(By.LinkText("Jurídica")).Click();
            //Informa CNPJ
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_cpf_cnpj")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_cpf_cnpj")).SendKeys("16.930.071/0001-23");
            //Data de Nascimento
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_data_nascimento")).Click();
            driver.FindElement(By.CssSelector(".today")).Click();
            //Ponto de venda
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_pto_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_pto_codigo")).SendKeys("matriz");
            driver.FindElement(By.LinkText("MATRIZ")).Click();
            //Vendedor
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_vend_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_vend_codigo")).SendKeys("francisco");
            driver.FindElement(By.LinkText("FRANCISCO")).Click();
            //Origem
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cliori_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cliori_codigo")).SendKeys("geral");
            driver.FindElement(By.LinkText("GERAL")).Click();
            //Sroll na tela
            driver.ExecuteJavaScript("window.scroll(0,1000)");
            //Endereço
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_tpender_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_tpender_codigo")).SendKeys("residencial");
            driver.FindElement(By.LinkText("Residencial")).Click();
            driver.FindElement(By.Id("campoCep")).Click();
            driver.FindElement(By.Id("campoCep")).SendKeys("84025-350");
            //Quando digita o CEP ele carrega a tela para trazer o endereço
            {
                var     element = driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_ender_numero"));
                Actions builder = new Actions(driver);
                builder.MoveToElement(element).ClickAndHold().Perform();
            }
            {
                var     element = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder = new Actions(driver);
                builder.MoveToElement(element).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_ender_numero")).SendKeys("350");
            //Salvar
            driver.FindElement(By.CssSelector("div:nth-child(2) > .btn > span:nth-child(2)")).Click();
        }
コード例 #7
0
        public void CadastraNegocio()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }
            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            #region Cadastro do Negócio
            //Central de Negocios
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[2]/div/a[1]/div/div")).Click();
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".btn-success")).Click();
            //Criando o negocio
            System.Threading.Thread.Sleep(6000);//Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".col-lg-3:nth-child(2) .ng-valid-mask")).Click();
            driver.FindElement(By.CssSelector(".col-lg-3:nth-child(2) .ng-valid-mask")).SendKeys("300.300.300-30");
            driver.FindElement(By.CssSelector(".col-lg-3:nth-child(3) #comboundefined")).Click();
            driver.FindElement(By.CssSelector(".col-lg-8:nth-child(1) .card-body")).Click();
            driver.ExecuteJavaScript("window.scroll(0,1000)");
            System.Threading.Thread.Sleep(3000);
            MetodosNavega.NavegaScroll(driver, "//*[@id=\"comboundefined\"]", 2);
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[3]/div[2]/div/div[2]/div[2]/div[1]/vs-editavel3/div/input")).Click();
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[3]/div[2]/div/div[2]/div[2]/div[1]/vs-editavel3/div/input")).SendKeys("aero");
            driver.FindElement(By.LinkText("AERONAUTICO")).Click();
            driver.FindElement(By.CssSelector(".col-lg-3:nth-child(3) .empty")).Click();
            driver.FindElement(By.CssSelector(".today")).Click();
            driver.FindElement(By.CssSelector(".col-lg-12 #combopontos")).Click();
            //driver.ExecuteScript("document.getElementById("combopontos").select()");
            driver.FindElement(By.CssSelector(".col-lg-12 #combopontos")).SendKeys("m");
            driver.FindElement(By.CssSelector(".col-lg-12 #combopontos")).SendKeys("a");
            driver.FindElement(By.CssSelector(".col-lg-12 #combopontos")).SendKeys("t");
            driver.FindElement(By.CssSelector(".col-lg-12 #combopontos")).SendKeys("r");
            driver.FindElement(By.CssSelector(".col-lg-12 #combopontos")).SendKeys("i");
            driver.FindElement(By.CssSelector(".col-lg-12 #combopontos")).SendKeys("z");
            System.Threading.Thread.Sleep(2000);
            driver.FindElement(By.LinkText("MATRIZ")).Click();
            driver.FindElement(By.Id("combovendedor")).Click();
            driver.FindElement(By.Id("combovendedor")).SendKeys("F");
            driver.FindElement(By.Id("combovendedor")).SendKeys("R");
            driver.FindElement(By.Id("combovendedor")).SendKeys("A");
            driver.FindElement(By.Id("combovendedor")).SendKeys("N");
            driver.FindElement(By.Id("combovendedor")).SendKeys("C");
            driver.FindElement(By.Id("combovendedor")).SendKeys("I");
            driver.FindElement(By.Id("combovendedor")).SendKeys("S");
            driver.FindElement(By.Id("combovendedor")).SendKeys("C");
            driver.FindElement(By.Id("combovendedor")).SendKeys("O");
            //driver.FindElement(By.Id("combovendedor")).Click();
            System.Threading.Thread.Sleep(2000);
            driver.FindElement(By.LinkText("FRANCISCO")).Click();
            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();
            //js.ExecuteScript("window.scrollTo(0,574)");

            //Fecha o navegador

            #endregion

            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: aburyndina/Animal
        static void Main(string[] args)
        {
            //var driver3 = new ChromeDriver("");
            var driver = new ChromeDriver(@"C:\Program Files\2.23.1\net40\chromedriver_win32", new ChromeOptions()
            {
            });
            //var driver = new InternetExplorerDriver(@"C:\Program Files\2.23.1");
            string baseURL = "http://*****:*****@type='submit' and @value='Найти']"));

            searchButton.Click();

            //создание животного
            IWebElement addAnimal = driver.FindElement(By.XPath("//input[@type='submit' and @value='Создать животное']"));

            addAnimal.Click();
            Thread.Sleep(100);

            driver.FindElement(By.LinkText("Обратно")).Click();
            Thread.Sleep(100);
            driver.FindElement(By.XPath("//input[@type='submit' and @value='Создать животное']")).Click();
            Thread.Sleep(100);

            var animalName = driver.FindElement(By.Id("AnimalName"));

            animalName.Click();
            animalName.Clear();
            string anName = "Пантера";

            animalName.SendKeys(anName);
            string xpathAnimalType = string.Format(".//option[contains(text(), '{0}' )]", "Млекопитающие");

            driver.FindElement(By.Id("TypeId")).FindElement(By.XPath(xpathAnimalType)).Click();
            driver.FindElement(By.Id("FellColorId")).FindElement(By.XPath(".//option[contains(text(),'черная')]")).Click();
            driver.FindElement(By.Id("RegionId")).FindElement(By.XPath(".//option[contains(text(),'Германия')]")).Click();
            Thread.Sleep(100);
            driver.FindElement(By.Id("LocationId")).FindElement(By.XPath(".//option[contains(text(),'Кельн')]")).Click();
            driver.FindElement(By.XPath("//input[@type='submit' and @value='Сохранить']")).Click();
            Thread.Sleep(100);

            //Поиск с checkbox
            var result = driver.ExecuteJavaScript <string>("var rl = $('#regionList'); rl.multiselect('open'); rl.multiselect('uncheckAll'); return '0';");

            driver.FindElement(By.XPath(".//span[contains(text(),'Германия')]")).Click();

            driver.FindElement(By.Id("TypeId")).FindElement(By.XPath(".//option[contains(text(),'Млекопитающие')]")).Click();
            driver.FindElement(By.Id("FellColorId")).FindElement(By.XPath(".//option[contains(text(),'черная')]")).Click();
            driver.FindElement(By.XPath("//input[@type='submit' and @value='Найти']")).Click();
            Thread.Sleep(100);

            IWebElement animalTable = driver.FindElement(By.Id("Animal"));
            ReadOnlyCollection <IWebElement> allRows = animalTable.FindElements(By.TagName("tr"));
            var deleteLink = new List <string>();

            for (int i = 0; i < allRows.Count; i++)
            {
                ReadOnlyCollection <IWebElement> cells = allRows[i].FindElements(By.TagName("td"));

                for (int j = 0; j < cells.Count; j++)
                {
                    if (j > 1)
                    {
                        break;
                    }
                    var value = allRows[i].FindElements(By.TagName("td"))[j];

                    if (j == 0 && value.Text == anName)
                    {
                        // deleteLinkId = value.GetAttribute("href");
                        //deleteLinkId = allRows[i].FindElements(By.LinkText("Удалить"));
                        deleteLink.Add(allRows[i].FindElement(By.LinkText("Удалить")).GetAttribute("href"));
                    }
                    if (j == 1 && !value.Text.Equals("Млекопитающие"))
                    {
                        Console.WriteLine("Неверный тип животного");
                    }
                }
            }

            var links = animalTable
                        .FindElements(By.TagName("tr"))
                        .Where(tr => tr.FindElements(By.TagName("td")).Any(td => td.Text == anName))
                        .Select(tr => tr.FindElement(By.LinkText("Удалить")).GetAttribute("href"))
                        .ToList();


            //удаляем животное
            //var deleteLink = string.Format("[href*='/Home/DeleteAnimal/{0}']", deleteLinkId);
            deleteLink.ForEach(d => driver.Navigate().GoToUrl(d));
            //driver.Navigate().GoToUrl(deleteLinkId);
            //driver.FindElement(By.CssSelector(deleteLinkId)).Click();

            driver.Close();
            Console.WriteLine("Finish");
            Console.ReadKey();

            //By bycss = By.CssSelector("input[type='checkbox'][name='vm-video-select-all']");
            //WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            //IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
            //{
            //    return d.FindElements(bycss).ToList().Find(e => e.Displayed);
            //});

            //myDynamicElement.Click();
        }
コード例 #9
0
        public static void RemoveElement(this ChromeDriver driver, IWebElement element)
        {
            var xpath = driver.GetElementXPath(element);

            driver.ExecuteJavaScript($"return ({JavaScriptSugar.DocumentGetElementByXpath(xpath)}).remove()");
        }
コード例 #10
0
        public void CadastraPJApolice()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }
            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            #region Cadastrar Apolice PJ
            //Busca do cliente
            System.Threading.Thread.Sleep(3000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[1]/vs-portal-consultas-directive/div/div/div/div[3]/div")).Click();
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[1]/vs-portal-consultas-directive/div/div/div/div[3]/div/input")).SendKeys("monstros sa");

            System.Threading.Thread.Sleep(3000);//Aguardando a pagina carregar
            //Clicar na busca
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div:nth-child(1) > vs-portal-consultas-directive > div > div > div > div:nth-child(3) > div > span > button")).Click();

            //Clicar em Seguros
            System.Threading.Thread.Sleep(3000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div/div[2]/div/div/div[2]/div[1]/div/div[3]/div/div[1]/div/h3/a")).Click();
            driver.FindElement(By.XPath("//*[@id='menuTopo']/div[3]/div/vs-menu-responsivo/div/div[2]/div/div/ul/li[2]/a")).Click();

            //Clicar em incluir
            System.Threading.Thread.Sleep(2000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/vs-relacao3/div/div/div/div/div/div/div[1]/button")).Click();

            //Campo Apólice
            System.Threading.Thread.Sleep(2000);//Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_doc_apolice")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_doc_apolice")).SendKeys("123465");

            //Campo Seguradora
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_cia_codigo")).Click();
            driver.FindElement(By.LinkText("AMIL")).Click();

            //Campo Produto
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_ramo_codigo")).Click();
            driver.FindElement(By.LinkText("EMPRESARIAL")).Click();

            //Campo Origem
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_docori_codigo")).Click();
            driver.FindElement(By.LinkText("GERAL")).Click();

            //Campo Ponto de Venda
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).Clear();//Deixa o campo vazio
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).SendKeys("MATRIZ");
            driver.FindElement(By.LinkText("MATRIZ")).Click();

            //Campo data emissão
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_doc_data_emissao")).Click();
            driver.FindElement(By.CssSelector(".today")).Click();

            //Campo data de entrada
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_doc_data_entrada")).Click();
            System.Threading.Thread.Sleep(2000);//Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".today")).Click();

            //Salvar
            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();
            driver.ExecuteJavaScript("window.scrollTo(0,0)");



            #endregion

            //fechar o navegador saindo do quiverplus
            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #11
0
ファイル: ParserProcess.cs プロジェクト: Budya/WalmartParser
        public static List <Shoes> Parse()
        {
            var service = ChromeDriverService.CreateDefaultService(Environment.CurrentDirectory);
            var options = new ChromeOptions();
            //options.AddArguments("--headless");


            List <string> sourceUrls      = new List <string>();
            List <Shoes>  resultListShoes = new List <Shoes>();
            bool          comPrmt         = false;

            using (IWebDriver driver = new ChromeDriver(service, options))
            {
                driver.Url =
                    @"https://www.walmart.com/browse/clothing/mens-shoes/5438_1045804_1045807?page=1&ps=48#searchProductResult";

                WebDriverWait waitForElement = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                waitForElement.Until(ExpectedConditions.ElementIsVisible(By.ClassName("GlobalFooterCopyright")));

                IWebElement elem = driver.FindElement(By.ClassName("GlobalFooterCopyright"));

                driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", elem);

                // get count of pages for parsing
                var pagesWebElements =
                    driver.FindElement(By.ClassName("paginator-list")).FindElements(By.TagName("li"));
                var lastPage = pagesWebElements[pagesWebElements.Count - 1].FindElement(By.TagName("a")).Text;


                // !!!!!!! ONLY FOR TEST
                //int lastPageNum = Int32.Parse(lastPage);
                int lastPageNum = 1;
                int currentPage = 0;



                // creating a list of urls
                string urlFirstPart = @"https://www.walmart.com/browse/clothing/mens-shoes/5438_1045804_1045807?page=";
                string urlEndPart   = @"&ps=48#searchProductResult";
                for (int pageIterator = 1; pageIterator <= lastPageNum; pageIterator++)
                {
                    string walmartUrl = urlFirstPart + pageIterator + urlEndPart;
                    sourceUrls.Add(walmartUrl);
                }

                foreach (var sourceUrl in sourceUrls)
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();

                    currentPage = currentPage + 1;
                    driver.Url  = sourceUrl;

                    WebDriverWait waitForElement1 = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                    waitForElement1.Until(ExpectedConditions.ElementIsVisible(By.ClassName("GlobalFooterCopyright")));
                    IWebElement elem1 = driver.FindElement(By.ClassName("GlobalFooterCopyright"));

                    driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", elem1);

                    var elements = driver.FindElement(By.ClassName("search-result-gridview-items"))
                                   .FindElements(By.ClassName("Grid-col"));



                    foreach (var webElement in elements)
                    {
                        Shoes shoes = new Shoes();
                        if (comPrmt)
                        {
                            Console.WriteLine(webElement.FindElement(By.TagName("img"))
                                              .GetAttribute("data-image-src"));
                        }

                        // img link
                        shoes.ShoesImageUrl = webElement.FindElement(By.TagName("img"))
                                              .GetAttribute("data-image-src");
                        try
                        {
                            if (comPrmt)
                            {
                                Console.WriteLine(webElement.FindElement(By.ClassName("product-brand"))
                                                  .FindElement(By.TagName("strong")).Text);
                            }

                            // Brand name
                            shoes.ShoesBrand = webElement.FindElement(By.ClassName("product-brand"))
                                               .FindElement(By.TagName("strong")).Text;
                        }
                        catch (Exception e)
                        {
                            if (comPrmt)
                            {
                                Console.WriteLine("No Brand Name");
                            }

                            shoes.ShoesBrand = "No Brand Name";
                        }

                        if (comPrmt)
                        {
                            Console.WriteLine(webElement.FindElement(By.TagName("img"))
                                              .GetAttribute("alt"));
                        }

                        // Shoes title
                        shoes.ShoesTitle = webElement.FindElement(By.TagName("img"))
                                           .GetAttribute("alt");

                        //try
                        //{
                        //    var selectors = webElement.FindElement(By.ClassName("swatch-selector"))
                        //        .FindElements(By.TagName("button"));
                        //    foreach (var selector in selectors)
                        //    {
                        //        if (comPrmt)
                        //        {
                        //            Console.WriteLine(selector.FindElement(By.TagName("img")).GetAttribute("alt"));
                        //        }

                        //        // shoes variants
                        //        string str = selector.FindElement(By.TagName("img")).GetAttribute("alt");
                        //        shoes.ShoesVariants.Add(str);
                        //    }
                        //}
                        //catch (Exception e)
                        //{
                        //    //Console.WriteLine(e.Message);

                        //    shoes.ShoesVariants.Add("No Variants");
                        //}

                        try
                        {
                            if (comPrmt)
                            {
                                Console.WriteLine(webElement.FindElement(By.ClassName("price-group"))
                                                  .GetAttribute("aria-label"));
                            }

                            shoes.ShoesPrice = webElement.FindElement(By.ClassName("price-group"))
                                               .GetAttribute("aria-label");
                        }
                        catch (Exception e)
                        {
                            if (comPrmt)
                            {
                                Console.WriteLine("Out of Stock");
                            }

                            shoes.ShoesPrice = "Out of Stock";
                            //throw;
                        }

                        resultListShoes.Add(shoes);
                    }

                    stopwatch.Stop();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Page {0} from {1} is parsed in {2:hh\\:mm\\:ss}", currentPage, lastPageNum,
                                      stopwatch.Elapsed);
                    Console.ResetColor();
                }

                return(resultListShoes);
            }
        }
コード例 #12
0
        public void CadastraSinistro()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }
            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            #region Cadastrar Sinistro
            //Seleciona o campo de busca
            System.Threading.Thread.Sleep(3000);
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[1]/vs-portal-consultas-directive/div/div/div/div[3]/div")).Click();
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[1]/vs-portal-consultas-directive/div/div/div/div[3]/div/input")).SendKeys("fausto silva");

            //Clicar no busca
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div:nth-child(1) > vs-portal-consultas-directive > div > div > div > div:nth-child(3) > div > span > button")).Click();

            //Seleciona o cliente na lista
            System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div > div > div.col-sm-12.col-lg-9 > div > div > div:nth-child(2) > div.col-lg-12.col-md-12.col-sm-12 > div > div.card-body.card-padding.ng-scope > div > div:nth-child(1) > div > h3 > a")).Click();

            //Clicar em seguros
            System.Threading.Thread.Sleep(3000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[1]/nav/div[3]/div/vs-menu-responsivo/div/div[2]/div/div/ul/li[2]/a")).Click();

            //Acessar um documento
            System.Threading.Thread.Sleep(3000);
            driver.FindElement(By.CssSelector("tbody > tr.odd > td:nth-child(1) > button")).Click();

            //Clicar em sinistros
            System.Threading.Thread.Sleep(3000);
            driver.FindElement(By.CssSelector("div.col-xs-10.col-sm-10.col-lg-10.tab-menu-topo > div > vs-menu-responsivo > div > div.scrtabs-tabs-fixed-container > div > div > ul > li:nth-child(2) > a")).Click();

            //Clicar em incluir
            System.Threading.Thread.Sleep(3000);
            driver.FindElement(By.CssSelector(".btn-raised")).Click();
            driver.ExecuteJavaScript("window.scroll(0,100)");

            //Clicar em data do sinistro
            System.Threading.Thread.Sleep(3000);
            driver.FindElement(By.Name("frmAutoFormdocumentosSinistrosundefined_edt_sin_data_sinistro")).Click();
            driver.FindElement(By.CssSelector(".today")).Click();

            //Gravar
            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();
            #endregion
            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #13
0
        public static void BaixarFinanceiros(Cliente xCliente, IEnumerable <Financeiro> xFinanceiroLista)
        {
            bool ErrorDownload = false;

            foreach (var financeiro in xFinanceiroLista.Where(financeiro => financeiro.AtivoFinanceiro))
            {
                var optionsChr = new ChromeOptions();
                optionsChr.AddArgument("--ignore-certificate-errors");
                optionsChr.AddArgument("--ignore-ssl-errors");

                // Inicializa o Chrome Driver
                using (var driver = new ChromeDriver(optionsChr))
                {
                    try
                    {
                        if (Ferramentas.LogarSistema(driver, xCliente))
                        {
                            driver.Navigate().GoToUrl(Settings.Default.Financeiro);

                            driver.Navigate().Refresh();
                            Thread.Sleep(5000);

                            // Fecha o Popup
                            if (Ferramentas.ValidarElementoSeExiste(driver, "ilabspush-btn-close", "ClassName"))
                            {
                                driver.FindElementByClassName("ilabspush-btn-close").Click();
                            }

                            Ferramentas.LimparPastaDownload(Settings.Default.Download,
                                                            financeiro.NomeArquivo);
                            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));

                            // Setar a aba do financeiro
                            var tabFinan = driver.FindElementById("extrato");
                            switch (financeiro.NomeFinanceiro.ToUpper())
                            {
                            case "EXTRATO":
                                tabFinan = driver.FindElementById("extrato");
                                break;

                            case "DESPESAS":
                                tabFinan = driver.FindElementById("contasApagar");
                                break;

                            case "RECEITAS":
                                tabFinan = driver.FindElementById("contasAreceber");
                                break;
                            }

                            // As vezes aparece um popup em cima do elemento e com isso é necessário forçar uma execução em JS.
                            driver.ExecuteJavaScript("arguments[0].click();", tabFinan);

                            // Setar a data
                            var inputDateIn =
                                wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(
                                               driver.FindElementById("dataini")));
                            inputDateIn.Click();
                            inputDateIn.Clear();

                            var dataInitial     = new DateTime(2018, 1, 1);
                            var dateInitialUser = (xCliente.DataInicioFinanceiro.Trim().Length == 7
                                ? dataInitial.ToString("0" + xCliente.DataInicioFinanceiro)
                                : dataInitial.ToString(xCliente.DataInicioFinanceiro));

                            // O site valida se a data inicial e a data final tem mais de 365 dias de <>, caso tenha eu tiro 365 da data atual e não pego a data do usuário
                            inputDateIn.SendKeys(Ferramentas.ValidarMaior365Dias(
                                                     int.Parse(dateInitialUser.Substring(0, 2)),
                                                     int.Parse(dateInitialUser.Substring(2, 2)),
                                                     int.Parse(dateInitialUser.Substring(4, 4)))
                                ? (DateTime.Now.AddDays(-365)).ToString("    ddMMyyyy")
                                : dateInitialUser);

                            Thread.Sleep(1000);

                            // Setar Contas Bancarias
                            switch (financeiro.ContasBancarias.ToUpper())
                            {
                            case "TODOS":
                                driver.FindElementByXPath("//*[@id='conta_bancaria']/option[1]").Click();
                                break;

                            case "CAIXA":
                                driver.FindElementByXPath("//*[@id='conta_bancaria']/option[2]").Click();
                                break;

                            case "AVECPASS":
                                // Caso não tenha esta opção, vai para o próximo.
                                if (Ferramentas.ValidarElementoSeExiste(driver,
                                                                        "//*[@id='conta_bancaria']/option[3]", "XPath"))
                                {
                                    driver.FindElementByXPath("//*[@id='conta_bancaria']/option[3]").Click();
                                }
                                else
                                {
                                    continue;
                                }

                                break;
                            }

                            // Setar tipo de conta
                            switch (financeiro.TipoData.ToUpper())
                            {
                            case "QUITAÇÃO":
                                driver.FindElementByXPath("//*[@id='campoRefinarBusca']/label[4]/select/option[1]")
                                .Click();
                                break;

                            case "COMPETÊNCIA":
                                driver.FindElementByXPath("//*[@id='campoRefinarBusca']/label[4]/select/option[2]")
                                .Click();
                                break;

                            case "VENCIMENTO":
                                driver.FindElementByXPath("//*[@id='campoRefinarBusca']/label[4]/select/option[3]")
                                .Click();
                                break;
                            }

                            // Selecionar Bruto/Lí­quido
                            switch (financeiro.TipoValor.ToUpper())
                            {
                            case "BRUTO":
                                driver.FindElementByXPath("//*[@id='campoRefinarBusca']/label[7]/label[1]").Click();
                                break;

                            case "LÍQUIDO":
                                driver.FindElementByXPath("//*[@id='campoRefinarBusca']/label[7]/label[2]").Click();
                                break;
                            }

                            // Executar a busca
                            driver.FindElementByXPath("//*[@id='divExtrato']/form/div[2]/a").Click();

                            var waitTable = new WebDriverWait(driver, TimeSpan.FromSeconds(120));
                            waitTable.Until(
                                SeleniumExtras.WaitHelpers.ExpectedConditions.VisibilityOfAllElementsLocatedBy(
                                    By.ClassName("sorting_1")));

                            Thread.Sleep(10000);

                            // Baixar Relatorio
                            driver.FindElementByClassName("buttons-html5").Click();

                            Thread.Sleep(5000);

                            // Move o relatório baixado para a pasta do respectivo cliente
                            Ferramentas.MoverFinanceiroPasta(Settings.Default.CaminhoDestinoFinanceiros,
                                                             xCliente.NomeCliente, financeiro.NomeArquivo, financeiro.NomeFinanceiro,
                                                             financeiro.ContasBancarias, financeiro.TipoData, financeiro.TipoValor);

                            // Atualiza data da ultima execução com sucesso do cliente e valida se quem chamou foi a rotina de erros
                            if (!ErrorDownload)
                            {
                                ServiceCliente.AtualizarCliente(xCliente.NomeCliente, false, false, true);
                            }
                        }
                        else
                        {
                            throw new ArgumentException("Erro ao logar usuário.");
                        }
                    }
                    catch (Exception ex)
                    {
                        ServiceCliente.AtualizarCliente(xCliente.NomeCliente, true, false, true);
                        Ferramentas.GravarLog("BaixarFinanceiros - " + financeiro.NomeArquivo + " / Cliente: " + xCliente.NomeCliente, ex);
                        ErrorDownload = true;
                    }
                    finally
                    {
                        driver.Close();
                        driver.Quit();
                    }
                }
            }
        }
コード例 #14
0
        static void Main(string[] args)
        {
            // Options are used for setting "browser capabilities", such as setting a User-Agent
            // property as shown below:
            // var options = new
            //options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0");
            //options.AddAdditionalCapability("applicationCacheEnabled", false);

            // Services are used for setting up the WebDriver to your likings, such as
            // hiding the console window and restricting image loading as shown below:
            //var service = PhantomJSDriverService.CreateDefaultService(Environment.CurrentDirectory);
            //service.HideCommandPromptWindow = true;
            //service.LoadImages = false;
            var service = ChromeDriverService.CreateDefaultService(Environment.CurrentDirectory);
            var options = new ChromeOptions();
            //options.AddArguments("--headless");

            List <string> sourceUrls      = new List <string>();
            List <Shoes>  resultListShoes = new List <Shoes>();

            IWebDriver driver = new ChromeDriver(service, options);

            driver.Url = @"https://www.walmart.com/browse/clothing/mens-shoes/5438_1045804_1045807?page=1&ps=48#searchProductResult";

            WebDriverWait waitForElement = new WebDriverWait(driver, TimeSpan.FromSeconds(5));

            waitForElement.Until(ExpectedConditions.ElementIsVisible(By.ClassName("GlobalFooterCopyright")));

            IWebElement elem = driver.FindElement(By.ClassName("GlobalFooterCopyright"));

            driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", elem);

            // get count of pages for parsing
            var pagesWebElements = driver.FindElement(By.ClassName("paginator-list")).FindElements(By.TagName("li"));
            var lastPage         = pagesWebElements[pagesWebElements.Count - 1].FindElement(By.TagName("a")).Text;


            // !!!!!!! ONLY FOR TEST
            //int lastPageNum = Int32.Parse(lastPage);
            int lastPageNum = 5;


            // creating a list of urls
            string urlFirstPart = @"https://www.walmart.com/browse/clothing/mens-shoes/5438_1045804_1045807?page=";
            string urlEndPart   = @"&ps=48#searchProductResult";

            for (int pageIterator = 1; pageIterator <= lastPageNum; pageIterator++)
            {
                string walmartUrl = urlFirstPart + pageIterator + urlEndPart;
                sourceUrls.Add(walmartUrl);
            }

            foreach (var sourceUrl in sourceUrls)
            {
                driver.Url = sourceUrl;

                WebDriverWait waitForElement1 = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                waitForElement1.Until(ExpectedConditions.ElementIsVisible(By.ClassName("GlobalFooterCopyright")));
                IWebElement elem1 = driver.FindElement(By.ClassName("GlobalFooterCopyright"));

                driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", elem1);

                var elements = driver.FindElement(By.ClassName("search-result-gridview-items"))
                               .FindElements(By.ClassName("Grid-col"));



                foreach (var webElement in elements)
                {
                    Shoes shoes = new Shoes();

                    Console.WriteLine(webElement.FindElement(By.TagName("img"))
                                      .GetAttribute("data-image-src")); //ссылка на изображение
                    shoes.ShoesImageUrl = webElement.FindElement(By.TagName("img"))
                                          .GetAttribute("data-image-src");
                    try
                    {
                        Console.WriteLine(webElement.FindElement(By.ClassName("product-brand"))
                                          .FindElement(By.TagName("strong")).Text);

                        shoes.ShoesBrand = webElement.FindElement(By.ClassName("product-brand"))
                                           .FindElement(By.TagName("strong")).Text;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("No Brand Name");
                        shoes.ShoesBrand = "No Brand Name";
                        //throw;
                    }

                    Console.WriteLine(webElement.FindElement(By.TagName("img"))
                                      .GetAttribute("alt")); // название ботинок

                    shoes.ShoesTitle = webElement.FindElement(By.TagName("img"))
                                       .GetAttribute("alt");

                    try
                    {
                        var selectors = webElement.FindElement(By.ClassName("swatch-selector")).FindElements(By.TagName("button"));
                        foreach (var selector in selectors)
                        {
                            Console.WriteLine(selector.FindElement(By.TagName("img")).GetAttribute("alt"));
                            string str = selector.FindElement(By.TagName("img")).GetAttribute("alt");
                            shoes.ShoesVariants.Add(str);
                        }
                    }
                    catch (Exception e)
                    {
                        //Console.WriteLine(e.Message);

                        shoes.ShoesVariants.Add("No Variants");
                    }

                    try
                    {
                        Console.WriteLine(webElement.FindElement(By.ClassName("price-group")).GetAttribute("aria-label"));
                        shoes.ShoesPrice = webElement.FindElement(By.ClassName("price-group"))
                                           .GetAttribute("aria-label");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Out of Stock");
                        shoes.ShoesPrice = "Out of Stock";
                        //throw;
                    }

                    resultListShoes.Add(shoes);
                }
            }

            Console.ReadKey();
        }
コード例 #15
0
ファイル: CadastrarPJ.cs プロジェクト: franciscopdsjr/AutPlus
        public void CadastroDePJ()
        {
            #region Gera CNPJ
            string GerarCNPJ()
            {
                // Gerar 8 números aleatórios de 0 a 9 e 4 números (0001), e depois calcular eles
                // Colocar eles na maskedTextBox

                Random rnd = new Random();
                int    n1  = rnd.Next(0, 10);
                int    n2  = rnd.Next(0, 10);
                int    n3  = rnd.Next(0, 10);
                int    n4  = rnd.Next(0, 10);
                int    n5  = rnd.Next(0, 10);
                int    n6  = rnd.Next(0, 10);
                int    n7  = rnd.Next(0, 10);
                int    n8  = rnd.Next(0, 10);
                int    n9  = 0;
                int    n10 = 0;
                int    n11 = 0;
                int    n12 = 1;

                int Soma1 = n1 * 5 + n2 * 4 + n3 * 3 + n4 * 2 + n5 * 9 + n6 * 8 + n7 * 7 + n8 * 6 + n9 * 5 + n10 * 4 + n11 * 3 + n12 * 2;

                int DV1 = Soma1 % 11;

                if (DV1 < 2)
                {
                    DV1 = 0;
                }
                else
                {
                    DV1 = 11 - DV1;
                }

                int Soma2 = n1 * 6 + n2 * 5 + n3 * 4 + n4 * 3 + n5 * 2 + n6 * 9 + n7 * 8 + n8 * 7 + n9 * 6 + n10 * 5 + n11 * 4 + n12 * 3 + DV1 * 2;

                int DV2 = Soma2 % 11;

                if (DV2 < 2)
                {
                    DV2 = 0;
                }
                else
                {
                    DV2 = 11 - DV2;
                }

                return(n1.ToString() + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + n10 + n11 + n12 + DV1 + DV2);
            }

            #endregion

            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }

            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }
            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            #region Cadastrar PJ
            System.Threading.Thread.Sleep(2000); //Aguardando a pagina carregar
            driver.FindElement(By.Id("botaoMenu")).Click();
            System.Threading.Thread.Sleep(1000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("div:nth-child(3) > ul > li:nth-child(2) > a > span")).Click();
            System.Threading.Thread.Sleep(1000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div > div > form > div.paddingCard.col-lg-7.col-md-12.col-sm-12.col-xs-12 > div > div.clearfix.card-header.bg-card-teal > button")).Click();
            //Informa Nome
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_nome")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_nome")).SendKeys("MONSTROS SA");
            //Informa Tipo de Pessoa
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_tipo_pessoa")).Click();
            driver.FindElement(By.LinkText("Jurídica")).Click();
            //Informa CNPJ
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_cpf_cnpj")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_cpf_cnpj")).SendKeys(GerarCNPJ());
            //Data de Nascimento
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_data_nascimento")).Click();
            driver.FindElement(By.CssSelector(".today")).Click();
            //Ponto de venda
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_pto_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_pto_codigo")).SendKeys("matriz");
            driver.FindElement(By.LinkText("MATRIZ")).Click();
            //Vendedor
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_vend_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_vend_codigo")).SendKeys("francisco");
            driver.FindElement(By.LinkText("FRANCISCO")).Click();
            //Origem
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cliori_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cliori_codigo")).SendKeys("geral");
            driver.FindElement(By.LinkText("GERAL")).Click();
            //Sroll na tela
            driver.ExecuteJavaScript("window.scroll(0,1000)");
            //Endereço
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_tpender_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_tpender_codigo")).SendKeys("residencial");
            System.Threading.Thread.Sleep(1500);
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[1]/div/form/div[5]/div/div[2]/div[2]/div[1]/div/vs-editavel3/div/ul/li/a")).Click();
            System.Threading.Thread.Sleep(1500);
//            driver.FindElement(By.Id("campoCep")).Click();
            driver.FindElement(By.Id("campoCep")).SendKeys("84025-350");
            //Quando digita o CEP ele carrega a tela para trazer o endereço
            {
                var     element = driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_ender_numero"));
                Actions builder = new Actions(driver);
                builder.MoveToElement(element).ClickAndHold().Perform();
            }
            {
                var     element = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder = new Actions(driver);
                builder.MoveToElement(element).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_ender_numero")).SendKeys("350");
            //Salvar
            driver.FindElement(By.CssSelector("div:nth-child(2) > .btn > span:nth-child(2)")).Click();
            #endregion
            //Fecha o navegador
            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #16
0
        public void AutomacaoDeEmissao()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder  = new Actions(driver);
                //builder.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
            }

            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            #region Automação de emissão
            //Clica em Automação de emissão
            System.Threading.Thread.Sleep(4000);//Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("a:nth-child(4)")).Click();

            //Seleciona a cia
            System.Threading.Thread.Sleep(4000);               //Aguardando a pagina carregar
            driver.ExecuteJavaScript("window.scroll(0,1000)"); //Scroll na tela
            driver.FindElement(By.CssSelector("div:nth-child(9) > div > div.col-xs-10")).Click();

            //Desmarca
            System.Threading.Thread.Sleep(8000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[4]/div/div[1]/div/spam[2]")).Click();


            //Marcar somente um
            driver.ExecuteJavaScript("window.scrollTo(0,1000)");
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div > div:nth-child(4) > div > div.card-body.card-padding.row.scroll-arquivos > div > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(1) > vs-editavel3 > div > label > span")).Click();

            //Continuar
            driver.FindElement(By.CssSelector(".btn-md")).Click();

            //Clica para sair da mensagem
            System.Threading.Thread.Sleep(9000);//Aguardando a pagina carregar
            //ESC para fechar a tela de dados da importação
            Actions action = new Actions(driver);
            action.SendKeys(Keys.Escape).Perform();
            //driver.FindElement(By.CssSelector("div.ngdialog-overlay")).Click();

            //Gravar
            System.Threading.Thread.Sleep(2000);//Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".btn-md")).Click();

            //Editar (Lápis)
            System.Threading.Thread.Sleep(15000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[3]/div[1]/div[2]/table/tbody/tr/td[7]/div[1]/span[1]")).Click();

            //Ponto de venda
            driver.FindElement(By.CssSelector(".col-lg-12:nth-child(2) > .col-lg-3:nth-child(3) #comboundefined")).Click();
            driver.FindElement(By.CssSelector(".col-lg-12:nth-child(2) > .col-lg-3:nth-child(3) #comboundefined")).SendKeys("matriz");
            driver.FindElement(By.CssSelector("strong")).Click();

            //Origem
            driver.FindElement(By.CssSelector(".col-lg-12:nth-child(4) #comboundefined")).Click();
            driver.FindElement(By.CssSelector(".col-lg-12:nth-child(4) #comboundefined")).SendKeys("geral");
            driver.FindElement(By.CssSelector("strong")).Click();

            //Comissao
            driver.FindElement(By.CssSelector(".ng-invalid .form-control")).Click();
            for (int i = 0; i < 4; i++)
            {
                driver.FindElement(By.CssSelector(".ng-invalid .form-control")).SendKeys(Keys.Backspace);
            }
            driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[6]/div[1]/div[2]/vs-editavel3/div/input")).SendKeys("20,00");
            //driver.FindElement(By.CssSelector(".ng-invalid .form-control")).SendKeys(Keys.Delete);



            //Vendedor
            driver.ExecuteJavaScript("window.scroll(0,2000)");
            driver.FindElement(By.CssSelector(".row:nth-child(10) > .col-lg-12:nth-child(1) #comboundefined")).Click();
            driver.FindElement(By.CssSelector(".row:nth-child(10) > .col-lg-12:nth-child(1) #comboundefined")).SendKeys("francisco");
            driver.FindElement(By.CssSelector("strong")).Click();

            //Salvar
            driver.FindElement(By.CssSelector(".col-lg-12:nth-child(8) > .pull-right:nth-child(1)")).Click();
            #endregion

            //Fecha o navegador
            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #17
0
        public void CadastraEndosso()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }
            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            #region Cadastrar Endosso
            //Informa o nome do cliente a ser pesquisado
            System.Threading.Thread.Sleep(3000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[1]/vs-portal-consultas-directive/div/div/div/div[3]/div/input")).SendKeys("fausto silva");
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div:nth-child(1) > vs-portal-consultas-directive > div > div > div > div:nth-child(3) > div > span > button")).Click();

            //Seleciona o resultado
            System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div/div[2]/div/div/div[2]/div[1]/div/div[3]/div/div[1]/div/h3/a")).Click();

            //inicia cadastro de documento
            System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
            driver.FindElement(By.LinkText("Seguros")).Click();

            System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".btn-success")).Click();

            System.Threading.Thread.Sleep(3000);//Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_cia_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_cia_codigo")).SendKeys("AIG");
            driver.FindElement(By.LinkText("AIG")).Click();

            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_ramo_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_ramo_codigo")).SendKeys("automoveis");
            driver.FindElement(By.CssSelector("strong")).Click();

            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_docori_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_docori_codigo")).SendKeys("geral");
            driver.FindElement(By.CssSelector("strong")).Click();

            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).Clear();//Deixa o campo vazio
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).SendKeys("MATRIZ");
            driver.FindElement(By.LinkText("MATRIZ")).Click();

            System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();

            //aba seguro
            System.Threading.Thread.Sleep(15000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[1]/nav/div[3]/div/vs-menu-responsivo/div/div[2]/div/div/ul/li[1]/a")).Click();

            //Novo endosso
            System.Threading.Thread.Sleep(3000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[5]/div[2]/div/div[1]/button")).Click();

            System.Threading.Thread.Sleep(2000);//Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_tpmov_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_tpmov_codigo")).SendKeys("substituicao");
            driver.FindElement(By.LinkText("SUBSTITUICAO DE ITEM")).Click();

            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();
            driver.ExecuteJavaScript("window.scrollTo(0,123)");
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60); //Aguardando a pagina carregar
            System.Threading.Thread.Sleep(9000);                                //Aguardando a pagina carregar
            driver.FindElement(By.LinkText("Seguro")).Click();
            #endregion
            //Fecha o navegador
            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #18
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="url"></param>
    /// <param name="savePath"></param>
    /// <param name="pageSource"></param>
    /// <param name="log"></param>
    public static bool Run(string url, string savePath, out string pageSource, Action <object, Exception> log = null)
    {
        pageSource = null;
        try
        {
            var dir = $"{AppDomain.CurrentDomain.BaseDirectory.TrimEnd('/', '\\')}/Files";
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            var fileName = $"{dir}/{Guid.NewGuid()}";

            var option = new ChromeOptions();
            //option.AddArgument("--window-size=1920,1080");
            option.AddArgument("headless");
            var driver = new ChromeDriver(option);

            var win = driver.Manage().Window;

            log?.Invoke($"设置前窗口大小:{win.Size.Width} {win.Size.Height}", null);

            win.Size = new Size(1971, 1080);

            log?.Invoke($"设置后窗口大小:{win.Size.Width} {win.Size.Height}", null);

            driver.Navigate().GoToUrl(url);
            pageSource = driver.PageSource;
            var heightStr = driver.ExecuteJavaScript <object>("return document.documentElement.scrollHeight+\"|\"+document.documentElement.clientHeight+\"|\"+document.documentElement.clientWidth").ToString();

            var obj          = heightStr.Split('|');
            var scrollHeight = int.Parse(obj[0]);
            var clientHeight = int.Parse(obj[1]);
            var clientWidth  = int.Parse(obj[2]);

            var pageSize = scrollHeight / clientHeight;

            log?.Invoke($"Js获取窗口大小:{clientWidth}  {scrollHeight}  {clientHeight}", null);

            int index = 0;
            for (; index < pageSize; index++)
            {
                driver.ExecuteScript($"window.scrollTo(0,{clientHeight * index})");
                driver.ExecuteScript("var items=document.querySelectorAll('*');var array=[];for(var i=0;i<items.length;i++){var name=items[i].tagName.toLocaleLowerCase();var flag=false;for(var j=0;j<array.length;j++){if(array[j]===name){flag=true;break}}if(!flag){array.push(name)}}for(var i=0;i<array.length;i++){var tagName=array[i];var rows=document.getElementsByTagName(tagName);for(var j=0;j<rows.length;j++){var pt=window.getComputedStyle(rows[j],null).position;if(pt==='fixed'){rows[j].style.setProperty('position','absolute','important');rows[j].style.setProperty('top','','important');rows[j].style.setProperty('bottom','','important');rows[j].style.setProperty('left','','important');rows[j].style.setProperty('right','','important')}}};");

                // 通过截图文件MD5值判断是否加载完成
                var num = 0;
                var md5 = new List <string>();
                while (num < 50)
                {
                    var ph = $@"{fileName}{index}_{num}.jpg";
                    driver.GetScreenshot().SaveAsFile(ph, ScreenshotImageFormat.Jpeg);
                    var m5 = FileMd5(ph);
                    md5.Add(m5);
                    File.Delete(ph);

                    var c = md5.Count(p => p == m5);
                    if (c >= 3)
                    {
                        break;
                    }
                    num++;
                    Thread.Sleep(200);
                }

                driver.GetScreenshot().SaveAsFile($@"{fileName}{index}.jpg", ScreenshotImageFormat.Jpeg);
            }

            if (scrollHeight % clientHeight > 0)
            {
                driver.ExecuteScript($"window.scrollTo(0,{scrollHeight})");
                driver.GetScreenshot().SaveAsFile($@"{fileName}{index}.jpg", ScreenshotImageFormat.Jpeg);
            }
            driver.Close();
            driver.Dispose();

            var bmp = new Bitmap(clientWidth - (scrollHeight % clientHeight > 0 ? 18 : 0), scrollHeight);
            var g   = Graphics.FromImage(bmp);
            g.Clear(Color.White);

            var i = 0;
            for (; i < index; i++)
            {
                var img = Image.FromFile($@"{fileName}{i}.jpg");
                g.DrawImage(img, 0, i * clientHeight, clientWidth, clientHeight);
                img.Dispose();
            }

            if (scrollHeight % clientHeight > 0)
            {
                var img = Image.FromFile($@"{fileName}{i}.jpg");
                g.DrawImage(img, 0, scrollHeight - clientHeight, clientWidth, clientHeight);


                img.Dispose();
            }

            bmp.Save($@"{savePath}", ImageFormat.Jpeg);

            g.Dispose();
            bmp.Dispose();


            for (var j = 0; j <= i; j++)
            {
                File.Delete($@"{fileName}{j}.jpg");
            }

            return(true);
        }
        catch (Exception ex)
        {
            log?.Invoke(ex.Message, ex);
            return(false);
        }
    }
コード例 #19
0
ファイル: CadastrarPF.cs プロジェクト: franciscopdsjr/AutPlus
        public void CadastroPF()
        {
            #region Gera CPF
            String GerarCpf()
            {
                int soma = 0, resto = 0;

                int[] multiplicador1 = new int[9] {
                    10, 9, 8, 7, 6, 5, 4, 3, 2
                };
                int[] multiplicador2 = new int[10] {
                    11, 10, 9, 8, 7, 6, 5, 4, 3, 2
                };

                Random rnd     = new Random();
                string semente = rnd.Next(100000000, 999999999).ToString();

                for (int i = 0; i < 9; i++)
                {
                    soma += int.Parse(semente[i].ToString()) * multiplicador1[i];
                }

                resto = soma % 11;
                if (resto < 2)
                {
                    resto = 0;
                }
                else
                {
                    resto = 11 - resto;
                }

                semente = semente + resto;
                soma    = 0;

                for (int i = 0; i < 10; i++)
                {
                    soma += int.Parse(semente[i].ToString()) * multiplicador2[i];
                }

                resto = soma % 11;

                if (resto < 2)
                {
                    resto = 0;
                }
                else
                {
                    resto = 11 - resto;
                }

                semente = semente + resto;
                return(semente);
            }

            #endregion

            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
            }
            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            #region Cadastrar Cliente PF
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.Id("botaoMenu")).Click();
            System.Threading.Thread.Sleep(1000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("div:nth-child(3) > ul > li:nth-child(2) > a > span")).Click();
            System.Threading.Thread.Sleep(1000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div > div > form > div.paddingCard.col-lg-7.col-md-12.col-sm-12.col-xs-12 > div > div.clearfix.card-header.bg-card-teal > button")).Click();
            //Informa Nome
            System.Threading.Thread.Sleep(2000);//Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_nome")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_nome")).SendKeys("FAUSTO SILVA");
            //Informa CPF



            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_cpf_cnpj")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_cpf_cnpj")).SendKeys(GerarCpf());
            //Informa data nascimento
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cli_data_nascimento")).Click();
            driver.FindElement(By.CssSelector(".today")).Click();
            //Informa ponto de venda
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_pto_codigo")).Click();
            driver.FindElement(By.LinkText("MATRIZ")).Click();
            //Informa vendedor
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_vend_codigo")).Click();
            driver.FindElement(By.LinkText("FRANCISCO")).Click();
            //Informa Origem
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_cliori_codigo")).Click();
            driver.FindElement(By.LinkText("GERAL")).Click();

            driver.ExecuteJavaScript("window.scroll(0,1000)");//Executa js
            //Informa o endereço
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_tpender_codigo")).Click();
            driver.FindElement(By.LinkText("Residencial")).Click();
            //driver.FindElement(By.Id("campoCep")).Click();
            driver.FindElement(By.Id("campoCep")).SendKeys("84025-350");

            {
                var     element = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder = new Actions(driver);
                //builder.MoveToElement(element).Release().Perform();
            }
            //Salva
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.Name("frmAutoFormclientesundefined_edt_ender_numero")).SendKeys("350");
            driver.FindElement(By.CssSelector("div:nth-child(2) > .btn > span:nth-child(2)")).Click();
            #endregion
            //Fecha o navegador
            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #20
0
        public void RelacionamentosComCliente()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                try {
                    System.Threading.Thread.Sleep(5000);
                    var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                    Actions builder  = new Actions(driver);
                    System.Threading.Thread.Sleep(5000);
                    builder.MoveToElement(elemento).Release().Perform();
                }
                catch (Exception ex)
                {
                    IWebElement   comboBase  = driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select"));
                    SelectElement optionBase = new SelectElement(comboBase);
                    optionBase.SelectByValue("Main");
                }
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }
            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion



            #region Central de relacionamento
            System.Threading.Thread.Sleep(6000);     //Aguardando a pagina carregar
            driver.FindElement(By.Id("botaoMenu")).Click();
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("div:nth-child(3) > .menu > .menu-item:nth-child(8) > .menu-span > .ng-binding")).Click();
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".menu-item:nth-child(8) > .expandida > .menu > .menu-item:nth-child(1) > .menu-span > .ng-binding")).Click();
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".menu-item:nth-child(1) .menu-item:nth-child(1) .ng-binding")).Click();
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.Id("comboundefined")).Click();
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.Id("comboundefined")).SendKeys("francisco");
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector("strong")).Click();
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".form-group:nth-child(4) .check")).Click();
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormcentralRelacClientesSelecaoundefined_edt_data1")).Click();
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormcentralRelacClientesSelecaoundefined_edt_data1")).SendKeys("24/04/1994");
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormcentralRelacClientesSelecaoundefined_edt_data2")).Click();
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormcentralRelacClientesSelecaoundefined_edt_data2")).SendKeys("24/04/1994");
            System.Threading.Thread.Sleep(3000);     //Aguardando a pagina carregar
            {
                System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
                var element = driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[2]/div[2]/div"));
                System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
                Actions builder = new Actions(driver);
                System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
                builder.MoveToElement(element).Perform();
            }
            System.Threading.Thread.Sleep(5000); //Aguardando a pagina carregar
            driver.FindElement(By.LinkText("Dados do documento")).Click();
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormcentralRelacClientesSelecaoundefined_edt_doc_apolice")).Click();
            driver.FindElement(By.Name("frmAutoFormcentralRelacClientesSelecaoundefined_edt_doc_apolice")).Clear();
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            // driver.FindElement(By.Name("frmAutoFormcentralRelacClientesSelecaoundefined_edt_doc_apolice")).SendKeys("VariosItens");
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.ExecuteJavaScript("window.scroll(0,1000)");
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".btn-default")).Click();
            System.Threading.Thread.Sleep(5000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".check")).Click();
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".check")).Click();
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".check")).Click();
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".btn-default:nth-child(2)")).Click();
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".col-lg-3 > .ng-pristine span")).Click();
            System.Threading.Thread.Sleep(3000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".modal-footer > .btn")).Click();
            System.Threading.Thread.Sleep(5000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".col-sm-12 > .ng-pristine .ng-valid-maxlength")).Click();
            System.Threading.Thread.Sleep(8000); //Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/email/div/div/div[3]/div/div/div[2]/div[6]/vs-editavel3/div/input")).SendKeys("teste regressivo");
            System.Threading.Thread.Sleep(5000); //Aguardando a pagina carregar
            driver.FindElement(By.CssSelector(".mfb-component__main-icon--active")).Click();
            System.Threading.Thread.Sleep(5000);
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/email/ul/li/a")).Click();
            #endregion

            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #21
0
        static void Main(string[] args)
        {
            string     username = "******"; //You should write your instagram account mail orr username
            string     password = "******"; //You should write your instagram password
            IWebDriver driver   = new ChromeDriver();

            driver.Url = "https://www.instagram.com/";
            Thread.Sleep(5000);
            IWebElement userBar = driver.FindElement(By.Name("username"));
            IWebElement passBar = driver.FindElement(By.Name("password"));

            userBar.SendKeys(username);
            passBar.SendKeys(password);

            IWebElement button2 = driver.FindElements(By.TagName("button"))[1];

            button2.Click();
            Thread.Sleep(6000);

            IWebElement button3 = driver.FindElement(By.XPath("/html/body/div[4]/div/div/div[3]/button[2]"));

            button3.Click();

            driver.Url = "XXX";//You must paste the URL the person you want. With https
            Thread.Sleep(1000);

            IWebElement button4 = driver.FindElement(By.XPath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a"));

            button4.Click();
            Thread.Sleep(1000);

            driver.ExecuteJavaScript("function scpDt_stb2pp3(lastEntity, loadCount = -1) {     if(loadCount != -1)     {        var willFail = parseInt(document.evaluate(' / html / body / div[1] / section / main / div / header / section / ul" +
                                     " / li[2] / a / span', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.title.replace(',','').replace('.','')) < loadCount;        if(willFail)         {            console.log('NAIS');    " +
                                     "        return;        }    }        var target = loadCount == -1 ? parseInt(document.evaluate(' / html / body / div[1] / section / main / div / header / section / ul / li[2] / a / span', document, null, XPathResult" +
                                     ".FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.title.replace(',','').replace('.','')) : loadCount;    if(document.getElementsByClassName('PZuss')[0] == null || (document.getElementsByClassName('PZuss')[0].childEleme" +
                                     "ntCount+30) == lastEntity)     {         setTimeout(() => {            if(loadCount == -1)             {                scpDt_stb2pp3(lastEntity);            }            else scpDt_stb2pp3(lastEntity, l" +
                                     "oadCount);        }, 50);         return;     }     var targetRange = document.getElementsByClassName('PZuss')[0].childElementCount+30<target;    console.log(target);     console.log(targetRange);     if(targetRange)     {    " +
                                     "     setTimeout(() => {             document.getElementsByClassName('isgrP')[0].scrollTo(0,document.getElementsByClassName('isgrP')[0].scrollHeight);             if(loadCount == -1)             {             " +
                                     "   scpDt_stb2pp3(lastEntity);            }            else scpDt_stb2pp3(lastEntity, loadCount);        }, 50);     } } scpDt_stb2pp3(-1,35);");// NOTE: You can follow 35 people per hour. 35 is LIMIT. If you change the 35 number you could get banned for 12hr,24hr,36hr,48hr,60hr,72hr or PERMA.

            Thread.Sleep(15000);

            Console.WriteLine("For Loop Starting");

            for (int i = 1; i < 35; i++)
            {
                IWebElement button5 = driver.FindElement(By.XPath("/ html / body / div[4] / div / div[2] / ul / div / li[" + i + "] / div / div[2] / button"));
                if (button5.Text.Contains("Takip Et"))
                {
                    Console.WriteLine("Button will be pressed");
                    button5.Click();
                    while (!button5.Text.Contains("İstek Gönderildi") && !button5.Text.Contains("Takiptesin")) //Change these according to your own language
                    {
                        Thread.Sleep(8000);                                                                    //NOTE: 8 sec is a limit please dont change
                        Console.WriteLine("Waiting " + button5.Text);
                    }
                }
                else
                {
                    Console.WriteLine("Skipped");
                }
            }

            Console.ReadLine();
            driver.Quit();
        }
コード例 #22
0
        public void AutomacaoDeProposta()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            System.Threading.Thread.Sleep(8000);
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
            }
            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion
            bool sucesso = false;
            int  i       = 0;
            while (sucesso == false)
            {
                #region Automacao de Proposta
                System.Threading.Thread.Sleep(5000); //Aguardando a pagina carregar
                                                     //Seleciona Automação
                driver.FindElement(By.CssSelector(".icon-file-empty:nth-child(2)")).Click();

                //Seleciona a Cia
                System.Threading.Thread.Sleep(10000);//Aguardando a pagina carregar
                driver.FindElement(By.CssSelector("div:nth-child(8) > div > div.col-xs-10")).Click();

                //Desmarcar
                try
                {
                    System.Threading.Thread.Sleep(6000);//Aguardando a pagina carregar
                    driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[4]/div/div[2]/div/div[2]/table/tbody/tr[1]/td[1]/vs-editavel3/div/label")).Click();
                    //driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div > div:nth-child(4) > div > div.clearfix.card-header.bg-card-teal > div > spam:nth-child(2)")).Click();
                }
                catch (Exception ex)//Caso não tenha o botão desmarcar o sistema irá avisar
                {
                    i = 1;
                    break;

                    throw new Exception("Não há arquivos baixados pelo feeder" + Environment.NewLine + ex.Message + (ex.InnerException != null ? ex.InnerException.ToString() : String.Empty));
                }
                sucesso = true;

                driver.ExecuteJavaScript("window.scrollTo(0,1000)");


                //Marcar somente um
                driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div > div:nth-child(4) > div > div.card-body.card-padding.row.scroll-arquivos > div > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(1) > vs-editavel3 > div > label > span")).Click();

                //Continuar
                driver.FindElement(By.CssSelector(".btn-md")).Click();
                System.Threading.Thread.Sleep(50000);
                //Clique para sair mensagem
                System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
                Actions action = new Actions(driver);
                action.SendKeys(Keys.Escape).Perform();



                //Gravar
                System.Threading.Thread.Sleep(30000);//Aguardando a pagina carregar
                //if (driver.FindElement(By.XPath("//*[@id=\"ngdialog1\"]/div[1]")).Displayed) {
                // driver.FindElement(By.XPath("//*[@id=\"ngdialog1\"]/div[1]")).Click();
                /// }
                driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div[5]/div/div/button")).Click();
                System.Threading.Thread.Sleep(10000);
                bool validaExistCobertura = driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[1]/h3")).Displayed;
                if (validaExistCobertura)
                {
                    if (driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[1]/h3")).Text.ToString().Trim() == "Parametrização de coberturas e parâmetros de importação PDF")
                    {
                        string textoCobertura = driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[2]/div/div/table/tbody/tr/td[1]")).Text;
                        driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[2]/div/div/table/tbody/tr/td[2]/div[3]/div[1]/vs-editavel3/div/input")).SendKeys("cobertura geral robo");
                        driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[2]/div/div/table/tbody/tr/td[2]/div[3]/div[1]/vs-editavel3/div/input")).SendKeys(Keys.Tab);
                        driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[2]/div/div/table/tbody/tr/td[2]/div[3]/div[1]/vs-editavel3/div/input")).SendKeys(Keys.Tab);
                        driver.FindElement(By.XPath("/html/body/div[12]/div[2]/div[2]/div/button[1]")).Click();
                        string textoDeConfirmacao = driver.FindElement(By.XPath("/html/body/div[13]/div[2]/div[3]/div/div/div[1]/div[1]/label")).Text.Trim();
                        driver.FindElement(By.XPath("/html/body/div[13]/div[2]/div[3]/div/div/div[1]/div[2]/input")).SendKeys(textoDeConfirmacao);
                        driver.FindElement(By.XPath("/html/body/div[13]/div[2]/div[3]/div/div/div[2]/button")).Click();
                        System.Threading.Thread.Sleep(8000);
                    }
                }

                //Editar (lápis)
                System.Threading.Thread.Sleep(15000);//Aguardando a pagina carregar
                driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[3]/div[2]/div/div/button[2]")).Click();



                //Ponto de venda
                System.Threading.Thread.Sleep(15000);//Aguardando a pagina carregar
                driver.FindElement(By.CssSelector(".col-lg-12:nth-child(2) > .col-lg-3:nth-child(3) #comboundefined")).Click();
                driver.FindElement(By.CssSelector(".col-lg-12:nth-child(2) > .col-lg-3:nth-child(3) #comboundefined")).Clear();
                driver.FindElement(By.CssSelector(".col-lg-12:nth-child(2) > .col-lg-3:nth-child(3) #comboundefined")).SendKeys("matriz");
                driver.FindElement(By.CssSelector("strong")).Click();

                //Origem
                driver.FindElement(By.CssSelector(".col-lg-12:nth-child(4) #comboundefined")).Click();
                driver.FindElement(By.CssSelector(".col-lg-12:nth-child(4) #comboundefined")).Clear();
                driver.FindElement(By.CssSelector(".col-lg-12:nth-child(4) #comboundefined")).SendKeys("geral");
                driver.FindElement(By.CssSelector("strong")).Click();

                //Vendedor
                driver.ExecuteJavaScript("window.scroll(0,1000)");//Scroll na tela
                driver.FindElement(By.CssSelector(".row:nth-child(10) > .col-lg-12:nth-child(1) #comboundefined")).Click();
                driver.FindElement(By.CssSelector(".row:nth-child(10) > .col-lg-12:nth-child(1) #comboundefined")).SendKeys("francisco");
                driver.FindElement(By.CssSelector("strong")).Click();

                //Gravar documento
                driver.FindElement(By.CssSelector(".col-lg-12:nth-child(8) > .pull-right:nth-child(1)")).Click();

                #endregion
            }
            if (i == 1)
            {
                Assert.IsFalse(sucesso);
            }
            //Fecha o Navegador
            MetodosNavega.SairPlus(driver);

            driver.Quit();
        }
コード例 #23
0
        public void CadastraDocMaisVendedor()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(5000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento1 = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder1  = new Actions(driver);
                builder1.MoveToElement(elemento1).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builderA = new Actions(driver);
                builderA.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }
            Login login = new Login();

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys(login.RetornaUsuario());
            driver.FindElement(By.Id("senha")).SendKeys(login.RetornaSenha());
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            #region Cadastrar Documento com mais de um vendedor
            System.Threading.Thread.Sleep(5000); //Aguardando a pagina carregar
            //Busca o cliente
            System.Threading.Thread.Sleep(5000); //Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[1]/vs-portal-consultas-directive/div/div/div/div[3]/div")).Click();
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[1]/vs-portal-consultas-directive/div/div/div/div[3]/div/input")).SendKeys("fausto silva");
            //Clica na busca
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div:nth-child(1) > vs-portal-consultas-directive > div > div > div > div:nth-child(3) > div > span > button")).Click();

            //Selecionar o cliente buscado
            System.Threading.Thread.Sleep(6000); //Aguardando a pagina carregar
                                                 // driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div > div > div.col-sm-12.col-lg-9 > div > div > div:nth-child(2) > div.col-lg-12.col-md-12.col-sm-12 > div > div.card-body.card-padding.ng-scope > div > div:nth-child(1) > div > h3 > a")).Click();
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/div/div[2]/div/div/div[2]/div[1]/div/div[3]/div/div[1]/div/h3/a")).Click();
            System.Threading.Thread.Sleep(5000); //Aguardando a pagina carregar
            //Clicar em Seguros
            driver.FindElement(By.XPath("/html/body/div[5]/div[1]/nav/div[3]/div/vs-menu-responsivo/div/div[2]/div/div/ul/li[2]/a")).Click();

            System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
            //Clicar em Incluir
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div/vs-relacao3/div/div/div/div/div/div/div[1]/button")).Click();

            //Seleciona a cia
            System.Threading.Thread.Sleep(10000);//Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_cia_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_cia_codigo")).SendKeys("porto");
            driver.FindElement(By.CssSelector("strong")).Click();


            //Seleciona o Produto
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_ramo_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_ramo_codigo")).SendKeys("AERO");
            driver.FindElement(By.CssSelector("strong")).Click();

            //Seleciona Origem
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_docori_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_docori_codigo")).SendKeys("geral");
            driver.FindElement(By.CssSelector("strong")).Click();

            //Seleciona Ponto de Venda
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).Clear();//Limpar o Campo
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).SendKeys("matriz");
            driver.FindElement(By.CssSelector("strong")).Click();

            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_docori_codigo")).Click();
            //Salvar
            driver.FindElement(By.CssSelector(".container-fluid > .row")).Click();
            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();


            //MouseOver pra selecionar o Botão valores
            System.Threading.Thread.Sleep(15000);
            //driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).Click();
            //driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[4]/div[2]/div/i")).Click();
            //driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[4]/div[2]/a")).Click();

            driver.SwitchTo().Window(driver.WindowHandles[0]);
            var     element = driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[4]/div[2]/div/i"));
            Actions builder = new Actions(driver);
            builder.MoveToElement(element).Release().Perform();
            try
            {
                System.Threading.Thread.Sleep(500);
                driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[4]/div[2]/div/i")).Click();
                driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[4]/div[2]/a")).Click();
            }
            catch
            {
            }



            //Valores
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[4]/div[2]/a")).Click();
            System.Threading.Thread.Sleep(3000);
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[5]/div[3]/div[2]/div/div/vs-botoes3/div/div/div[1]/button[1]")).Click();

            //Parcelas
            System.Threading.Thread.Sleep(8000);//Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_qtd_parcelas")).SendKeys("5,0");

            //Comissão Total
            driver.ExecuteJavaScript("window.scroll(0,1000)"); //Scroll na página
            System.Threading.Thread.Sleep(5000);               //Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_perc_comissao_total")).SendKeys(Keys.Control + "A");
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_perc_comissao_total")).SendKeys(Keys.Delete);
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_perc_comissao_total")).SendKeys("20,00");
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_perc_comissao")).SendKeys(Keys.Control + "A");
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_perc_comissao")).SendKeys(Keys.Delete);
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_perc_comissao")).SendKeys("20,00");

            //Premio
            //driver.ExecuteJavaScript("window.scroll(0,1000)");
            System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_premio_liquido")).SendKeys(Keys.Control + "A");
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_premio_liquido")).SendKeys(Keys.Delete);
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_premio_liquido")).SendKeys("2.000");
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_premio_total")).SendKeys(Keys.Control + "A");
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_premio_total")).SendKeys(Keys.Delete);
            driver.FindElement(By.Name("frmAutoFormdocumentosValoresundefined_edt_doc_premio_total")).SendKeys("2.147,60");


            //Salvar

            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();
            System.Threading.Thread.Sleep(10000);
            //Repasses
            var     element2 = driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[6]/div[2]/div/i"));
            Actions builder2 = new Actions(driver);
            builder2.MoveToElement(element2).Perform();

            System.Threading.Thread.Sleep(3000);
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[6]/div[2]/a")).Click();



            System.Threading.Thread.Sleep(3000);
            // driver.FindElement(By.XPath("/html/body/div[5]/div[1]/nav/div[1]/button[2]")).Click();

            System.Threading.Thread.Sleep(5000);
            //driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[6]/div[2]/a")).Click();
            System.Threading.Thread.Sleep(5000);
            driver.FindElement(By.XPath("/html/body/div[7]/div[2]/button[1]")).Click();
            System.Threading.Thread.Sleep(5000);
            //driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[6]/div[2]/a/span")).Click();
            // driver.FindElement(By.CssSelector(".confirm")).Click();

            //Incluir
            driver.FindElement(By.CssSelector(".btn-raised")).Click();
            driver.FindElement(By.Id("comboundefined")).Click();
            driver.FindElement(By.Id("comboundefined")).SendKeys("francisco teste");
            driver.FindElement(By.CssSelector("strong")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosRepasseundefined_edt_rep_percentual")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosRepasseundefined_edt_rep_percentual")).SendKeys("50");
            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();
            {
                var     element3 = driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[6]/div[2]/div"));
                Actions builder3 = new Actions(driver);
                builder3.MoveToElement(element3).Perform();
            }
            {
                var     element4 = driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[6]/div[2]/div"));
                Actions builder4 = new Actions(driver);
                builder4.MoveToElement(element4).Perform();
            }
            System.Threading.Thread.Sleep(2000);
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[6]/div[2]/a")).Click();
            //Cadastrando segundo vendedor
            System.Threading.Thread.Sleep(5000);//Aguardando a pagina carregar
            driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[4]/div[5]/div[2]/vs-relacao3/div/div/div/div/div/div/div[1]/button")).Click();
            driver.FindElement(By.Id("comboundefined")).SendKeys("f");
            driver.FindElement(By.Id("comboundefined")).SendKeys("r");
            driver.FindElement(By.Id("comboundefined")).SendKeys("a");
            driver.FindElement(By.Id("comboundefined")).SendKeys("n");
            driver.FindElement(By.Id("comboundefined")).SendKeys("c");
            driver.FindElement(By.LinkText("FRANCISCO")).Click();
            driver.FindElement(By.CssSelector("div:nth-child(1) > .col-md-6")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosRepasseundefined_edt_rep_percentual")).SendKeys("50");
            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();
            {
                var     element5 = driver.FindElement(By.XPath("/html/body/div[5]/div[2]/div[3]/div[1]/div/ul/li[6]/div[2]/div"));
                Actions builder5 = new Actions(driver);
                builder5.MoveToElement(element5).Perform();
            }
            #endregion
            driver.FindElement(By.XPath("//*[@id=\"menuTopo\"]/div[1]/a")).Click();
            System.Threading.Thread.Sleep(2000);
            //Fecha o navegador
            MetodosNavega.SairPlus(driver);
        }
コード例 #24
0
        public void TestMethod1()
        {
            #region Abrir o Chrome
            //inicializando o chrome
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://main.safety8.local/#/login?cnpj=72.408.271%2F0001-91");
            driver.Manage().Window.Maximize();
            System.Threading.Thread.Sleep(3000);
            #endregion

            #region Login
            var cnpj = driver.FindElement(By.Id("cnpj"));
            cnpj.SendKeys("72408271000191");
            {
                var     elemento = driver.FindElement(By.CssSelector(".logo-login-q"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).ClickAndHold().Perform();
            }
            {
                var     elemento = driver.FindElement(By.CssSelector(".efeitoOverlay"));
                Actions builder  = new Actions(driver);
                builder.MoveToElement(elemento).Release().Perform();
            }
            driver.FindElement(By.CssSelector(".container-fluid")).Click();
            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            {
                var dropdown = driver.FindElement(By.CssSelector(".ng-scope > .animated"));
                dropdown.FindElement(By.XPath("/html/body/div[5]/div[2]/div[2]/div/div/div/div/div/div[2]/div[2]/select/option[3]")).Click();
                //driver.Quit();
            }

            driver.FindElement(By.CssSelector(".ng-scope > .animated")).Click();
            driver.FindElement(By.Id("usuario")).Click();
            driver.FindElement(By.Id("usuario")).SendKeys("francisco");
            driver.FindElement(By.Id("senha")).SendKeys("F123456");
            driver.FindElement(By.CssSelector(".button-login-q")).Click();
            #endregion

            //Clicar no busca
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div:nth-child(1) > vs-portal-consultas-directive > div > div > div > div:nth-child(3) > div > input")).Click();
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div:nth-child(1) > vs-portal-consultas-directive > div > div > div > div:nth-child(3) > div > input")).Click();
            driver.FindElement(By.CssSelector("div:nth-child(5) > div.container-fluid > div:nth-child(3) > div.index-conteudo.ng-scope.animated.fadeIn.conteudo-geral > div:nth-child(1) > vs-portal-consultas-directive > div > div > div > div:nth-child(3) > div > input")).SendKeys("fausto silva");


            driver.FindElement(By.CssSelector(".zmdi-search")).Click();
            driver.FindElement(By.CssSelector(".list-virtual:nth-child(1) h3 > .ng-binding")).Click();
            driver.FindElement(By.LinkText("Seguros")).Click();
            driver.ExecuteJavaScript("window.scrollTo(0,47)");
            driver.FindElement(By.CssSelector(".btn-success")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_cia_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_cia_codigo")).SendKeys("porto");
            driver.FindElement(By.CssSelector("strong")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_ramo_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_ramo_codigo")).SendKeys("automoveis");
            driver.FindElement(By.LinkText("AUTOMOVEIS")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_docori_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_docori_codigo")).SendKeys("geral");
            driver.FindElement(By.LinkText("GERAL")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).Click();
            driver.FindElement(By.Name("frmAutoFormdocumentosundefined_edt_pto_codigo")).SendKeys("matriz");
            driver.FindElement(By.LinkText("MATRIZ")).Click();
            driver.FindElement(By.CssSelector("div:nth-child(2) > .botoes-bottom-verde")).Click();
            driver.ExecuteJavaScript("window.scrollTo(0,0)");
        }
コード例 #25
0
        public void GradeFile(string file, GradingTemplate template, StreamWriter reportStream)
        {
            double        possibleScore = template.PossiblePoints;
            double        score         = possibleScore;
            List <string> feedback      = new List <string>();
            bool          isBroken      = false;

            using (IWebDriver driver = new ChromeDriver())
            {
                string all_text = File.ReadAllText(file);

                reportStream.WriteLine("File: " + Path.GetFileName(file));
                reportStream.WriteLine();

                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
                string        url  = "file://" + file.Replace("\\", "/");
                driver.Navigate().GoToUrl(url);
                reportStream.WriteLine("===========================================");
                reportStream.WriteLine(all_text);
                reportStream.WriteLine("===========================================");
                reportStream.WriteLine();

                //ValidationResponse validation = ValidationCheck(all_text);
                //if (validation?.Messages?.Length > 0)
                //{
                //	score -= template.ValidationPenalty;
                //	feedback.Add("Validation Errors (-" + template.ValidationPenalty + "): ");
                //	foreach (Message msg in validation.Messages)
                //	{
                //		feedback.Add(msg.MessageMessage);
                //	}
                //}

                Dictionary <string, double> score_penalties = new Dictionary <string, double>();

                foreach (TestTemplate test in template.Tests)
                {
                    try
                    {
                        if (test.TestDateTime != DateTime.MinValue)
                        {
                            string jstring = "var d = new Date(" + test.TestDateTime.Year + ", " + (test.TestDateTime.Month - 1) + ", " + test.TestDateTime.Day + ");Date = function(){ return d};";
                            driver.ExecuteJavaScript(jstring);
                        }

                        ReadOnlyCollection <IWebElement> elements = driver.FindElements(By.XPath("html/body/input"));

                        if (elements.Count != test.Inputs.Count)
                        {
                            feedback.Add("Wrong number of inputs - expected: " + test.Inputs.Count + ", actual: " + elements.Count + "(-" + template.WrongNumberOfInputsPenalty + ")");

                            if (!score_penalties.ContainsKey("WrongNumberOfInputsPenalty"))
                            {
                                score_penalties.Add("WrongNumberOfInputsPenalty", template.WrongNumberOfInputsPenalty);
                            }

                            if (elements.Count < test.Inputs.Count)
                            {
                                if (!score_penalties.ContainsKey("InsufficientInputsPenalty"))
                                {
                                    score_penalties.Add("InsufficientInputsPenalty", template.InsufficientInputsPenalty);
                                }

                                isBroken = true;
                                break;
                            }
                        }

                        string inputs = "";
                        int    idx    = 0;
                        foreach (string input in test.Inputs)
                        {
                            inputs += input + " ";
                            elements[idx].Clear();
                            elements[idx].SendKeys(input);
                            idx++;
                        }
                        feedback.Add("Run with inputs: " + inputs);
                        IWebElement button = driver.FindElement(By.XPath("html/body/button"));
                        if (button == null)
                        {
                            feedback.Add("No button found. (-" + template.NoButtonPenalty + ")");

                            if (!score_penalties.ContainsKey("NoButtonPenalty"))
                            {
                                score_penalties.Add("NoButtonPenalty", template.NoButtonPenalty);
                            }

                            isBroken = true;
                            break;
                        }
                        button.Click();
                        Thread.Sleep(100);
                        IWebElement firstResult = driver.FindElement(By.XPath("html/body/div"));
                        if (firstResult == null)
                        {
                            feedback.Add("No div tag found. (-" + template.NoDivPenalty + ")");

                            if (!score_penalties.ContainsKey("NoDivPenalty"))
                            {
                                score_penalties.Add("NoDivPenalty", template.NoDivPenalty);
                            }
                        }

                        string actual = firstResult.GetAttribute("textContent");
                        if (!actual.Contains(test.ExpectedOutput) && test.AlternativeOutputs?.FindAll(o => actual.Contains(o)).FirstOrDefault() == null)
                        {
                            feedback.Add("Incorrect Output. (-" + template.IncorrectResponsePenalty + ")");

                            if (!score_penalties.ContainsKey("IncorrectResponsePenalty"))
                            {
                                score_penalties.Add("IncorrectResponsePenalty", template.IncorrectResponsePenalty);
                            }
                        }
                        feedback.Add("Expected: " + test.ExpectedOutput);
                        feedback.Add("Actual: " + actual);
                    }
                    catch
                    {
                        feedback.Add("Program doesn't run without errors. (-" + template.NoRunPenalty + ")");

                        if (!score_penalties.ContainsKey("NoRunPenalty"))
                        {
                            score_penalties.Add("NoRunPenalty", template.NoRunPenalty);
                        }
                    }
                }

                foreach (string key in score_penalties.Keys)
                {
                    score -= score_penalties[key];
                }

                if (score < template.MinimumSubmissionScore)
                {
                    score = template.MinimumSubmissionScore;
                }

                feedback.Add("Score: " + score + "/" + possibleScore);

                driver.Close();

                if (isBroken)
                {
                    feedback.Add("Program cannot run as written. (-" + template.NoRunPenalty + ")");
                }

                foreach (string line in feedback)
                {
                    reportStream.WriteLine(line);
                }
                reportStream.WriteLine();

                //reportStream.Close();
            }
        }