public static Folha[] CarregarFolhaFuncionarios(int[] cods, int mes, int ano)
        {
            // inicializa
            var valDate  = $"01/{mes:00}/{ano}";
            var lstfolha = new List <Folha>();

            using IWebDriver driver = new ChromeDriver();
            var ctr = new Controller(driver);

            // navega pro captcha e aguarda o preenchimento do primeiro
            ctr.Do(new Redirect(buildStartUrl(cods[0])));
            while (!ctr.ElementExists(By.ClassName("box_texto")))
            {
                Console.WriteLine("Definindo data");
                ctr.Interact(By.Name("fmes"), (d, e) =>
                {
                    var select = new OpenQA.Selenium.Support.UI.SelectElement(e);
                    select.SelectByValue(valDate);
                });

                Console.WriteLine("Aguardando captcha");
                //ctr.FindElement(By.TagName("h4"))
                ctr.WaitUntil_UserNavigate();
            }
            // reutiliza a sessão para consultar todos os outros
            foreach (var c in cods)
            {
                processaCodigo(lstfolha, ctr, c, new DateTime(ano, mes, 1));
            }

            return(lstfolha.ToArray());
        }
示例#2
0
        /// <summary>
        /// Select from a dropdown by value
        /// </summary>
        /// <param name="element">Select element</param>
        /// <param name="value">Option value</param>
        public static void SelectByValue(this IBrowser browser, SelectElement element, string value)
        {
            // Create selenium select element object
            var select = new OpenQA.Selenium.Support.UI.SelectElement(browser.Find(element));

            // Select by value
            select.SelectByValue(value);
        }
示例#3
0
        public void SelectAvalueFromAdropdown()
        {
            driver.Url = "http://demo.guru99.com/test/guru99home/";
            driver.Manage().Window.Maximize();

            IWebElement course = driver.FindElement(By.XPath(".//*[@id='awf_field-91977689']"));

            var selectTest = new OpenQA.Selenium.Support.UI.SelectElement(course);

            // Select a value from the dropdown
            selectTest.SelectByValue("sap-abap");
        }
        public void SetValue(string value, SelectMode selectMode)
        {
            if (selectMode == SelectMode.Value)
            {
                try
                {
                    _element.SelectByValue(value);
                }
                catch (NoSuchElementException)
                {
                    try
                    {
                        _element.SelectByText(value);
                    }
                    catch (NoSuchElementException)
                    {
                    }
                }
            }
            else if (selectMode == SelectMode.Text)
            {
                try
                {
                    _element.SelectByText(value);
                }
                catch (NoSuchElementException)
                {
                    throw new NoSuchElementException("Cannot locate option with text: " + value);
                }
            }
            else if (selectMode == SelectMode.Index)
            {
                try
                {
                    _element.SelectByIndex(Int32.Parse(value));
                }
                catch (NoSuchElementException)
                {
                    throw new NoSuchElementException("Cannot location option at index: " + value);
                }
            }

            this.OnChange();
        }
示例#5
0
        public bool selectByValue(By locator, string value, string locatorName)
        {
            bool flag = false;

            try
            {
                Select s = new Select(driver.FindElement(locator));
                s.SelectByValue(value);
                flag = true;
            }
            catch (Exception ex)
            {
                flag = false;
                System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(Path.Combine(projectLoc, TestContext.CurrentContext.Test.Name + "-" + DateTime.Now.ToString("dd-M-yyyy", CultureInfo.InvariantCulture) + "." + format), ScreenshotImageFormat.Jpeg);
                throw new Exception(ex.Message);
            }
            return(flag);
        }
        public void SetValues(Expression <Func <string, bool> > optionMatchingExpression, SelectMode selectMode)
        {
            var compiledFunc = optionMatchingExpression.Compile();

            if (selectMode == SelectMode.Value)
            {
                var options = _element.Options.Where(x => compiledFunc(x.GetAttribute("value"))).Select <IWebElement, string>(x => x.GetAttribute("value")).ToList();
                foreach (var optionValue in options)
                {
                    // dirty hack is dirty!
                    OpenQA.Selenium.Support.UI.SelectElement element = new OpenQA.Selenium.Support.UI.SelectElement(this.GetWebElement(true));
                    element.SelectByValue(optionValue);
                }

                if (options.Count() == 0)
                {
                    throw new SelectException("Selection failed. No option values matched expression [{0}] on element.", optionMatchingExpression.ToExpressionString());
                }
            }
            else if (selectMode == SelectMode.Text)
            {
                var options = _element.Options.Where(x => compiledFunc(x.Text)).Select <IWebElement, string>(x => x.Text).ToList();
                foreach (var optionText in options)
                {
                    // dirty hack is dirty!
                    OpenQA.Selenium.Support.UI.SelectElement element = new OpenQA.Selenium.Support.UI.SelectElement(this.GetWebElement(true));
                    element.SelectByText(optionText);
                }

                if (options.Count() == 0)
                {
                    throw new SelectException("Selection failed. No option text matched expression [{0}] on element.", optionMatchingExpression.ToExpressionString());
                }
            }

            this.OnChange();
        }
示例#7
0
        public void SetValues(Expression<Func<string, bool>> optionMatchingExpression, SelectMode selectMode)
        {
            var compiledFunc = optionMatchingExpression.Compile();
            if (selectMode == SelectMode.Value)
            {
                var options = _element.Options.Where(x => compiledFunc(x.GetAttribute("value"))).Select<IWebElement, string>(x => x.GetAttribute("value")).ToList();
                foreach (var optionValue in options)
                {
                    // dirty hack is dirty!
                    OpenQA.Selenium.Support.UI.SelectElement element = new OpenQA.Selenium.Support.UI.SelectElement(this.GetWebElement(true));
                    element.SelectByValue(optionValue);
                }

                if (options.Count() == 0)
                {
                    throw new SelectException("Selection failed. No option values matched expression [{0}] on element.", optionMatchingExpression.ToExpressionString());
                }
            }
            else if (selectMode == SelectMode.Text)
            {
                var options = _element.Options.Where(x => compiledFunc(x.Text)).Select<IWebElement, string>(x => x.Text).ToList();
                foreach (var optionText in options)
                {
                    // dirty hack is dirty!
                    OpenQA.Selenium.Support.UI.SelectElement element = new OpenQA.Selenium.Support.UI.SelectElement(this.GetWebElement(true));
                    element.SelectByText(optionText);
                }

                if (options.Count() == 0)
                {
                    throw new SelectException("Selection failed. No option text matched expression [{0}] on element.", optionMatchingExpression.ToExpressionString());
                }
            }

            this.OnChange();
        }