Exemplo n.º 1
0
 public SelectElement(IWebElement element, IWebDriver driver) : base(element, driver)
 {
     if (element.TagName == "select")
     {
         OldStyleSelect       = new OpenQA.Selenium.Support.UI.SelectElement(element);
         LazyAvailableOptions = new Lazy <IList <IWebElement> >(() => OldStyleSelect.Options);
         LazySelectedOptions  = new Lazy <IList <IWebElement> >(() => OldStyleSelect.AllSelectedOptions);
     }
     else
     {
         var listId = element.GetAttribute("list");
         if (string.IsNullOrWhiteSpace(listId))
         {
             throw new Exception("The {element.TagName} is neither a select element nor an element with a list attribute");
         }
         LazyAvailableOptions = new Lazy <IList <IWebElement> >(() => driver.FindElements(By.XPath($"//datalist[@id='{listId}']/option")));
         LazySelectedOptions  = new Lazy <IList <IWebElement> >(() => new List <IWebElement>());
         var value = element.GetAttribute("value");
         if (!string.IsNullOrWhiteSpace(value))
         {
             var selected = AvailableOptions.Where(o => o.GetAttribute("value") == value);
             if (selected.None())
             {
                 throw new Exception($"element with list:{listId} and value:{value} did not find any mathching options in the {AvailableOptions.Count()} options");
             }
             if (selected.Many())
             {
                 throw new Exception($"element with list:{listId} and value:{value} found {selected.Count()} mathching options in the {AvailableOptions.Count()} options");
             }
             SelectedOptions.Add(selected.First());
         }
     }
 }
        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());
        }
Exemplo n.º 3
0
        public void SelectValueByIndex(int index)
        {
            WaitForElementPresent();
            var select = new UISelectElement(GetElement());

            select.SelectByIndex(index);
        }
Exemplo n.º 4
0
        public void SelectValue(string value)
        {
            WaitForElementPresent();
            var select = new UISelectElement(GetElement());

            select.SelectByText(value);
        }
Exemplo n.º 5
0
        protected int ReturnAmountElementInComboBox(By locator)
        {
            OpenQA.Selenium.Support.UI.SelectElement comboBox = new OpenQA.Selenium.Support.UI.SelectElement(WaitForElement(locator));
            int count = comboBox.Options.Count;

            return(count);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Select from a dropdown by index
        /// </summary>
        /// <param name="element">Select element</param>
        /// <param name="text">Option index</param>
        public static void SelectByIndex(this IBrowser browser, SelectElement element, int value)
        {
            // Create selenium select element object
            var select = new OpenQA.Selenium.Support.UI.SelectElement(browser.Find(element));

            // Select by value
            select.SelectByIndex(value);
        }
Exemplo n.º 7
0
        public virtual TResult SelectedText <TResult>(string text) where TResult : IBlock
        {
            var select =
                new OpenQA.Selenium.Support.UI.SelectElement(Tag);

            select.SelectByText(text);
            return(Session.CurrentBlock <TResult>(ParentBlock.Tag));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Select from a dropdown by text
        /// </summary>
        /// <param name="element">Select element</param>
        /// <param name="text">Option text</param>
        public static void SelectByText(this IBrowser browser, SelectElement element, string text)
        {
            // Create selenium select element object
            var select = new OpenQA.Selenium.Support.UI.SelectElement(browser.Find(element));

            // Select by value
            select.SelectByText(text);
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="drdXpath"></param>
        /// <param name="searchValue">Unique full text of the option to search</param>
        public static void SelectValueFromDropdown(string drdXpath, string searchValue)
        {
            // select the drop down list
            var education = driver.FindElement(By.XPath(drdXpath));
            //create select element object
            var selectElement = new OpenQA.Selenium.Support.UI.SelectElement(education);

            // select by text
            selectElement.SelectByText(searchValue);
        }
Exemplo n.º 10
0
        public void PopulateMenu(string burgerType, string firstName)
        {
            this.additionalSugarCheckbox.Click();
            additionalSugarCheckbox.Click();
            var burgersSelect = new OpenQA.Selenium.Support.UI.SelectElement(burgersSelectElement);

            burgersSelect.SelectByText(burgerType);
            firstNameTextInput.Clear();
            firstNameTextInput.SendKeys(firstName);
        }
Exemplo n.º 11
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");
        }
Exemplo n.º 12
0
        private void Search(int row)
        {
            string valueToSearch = handle.GetNext(row, col);

            if (valueToSearch != null)
            {
                string textboxName       = "ctl00$ctl00$ctl00$BodyContent$ContentPlaceHolder1$MainContentPlaceHolder$ResourceHostControl1$resContainer$rptContainers$ctl00$rptColumn1$ctl00$ctl01$Wrapper$txtSearchString";
                string attributeDropdown = "ctl00$ctl00$ctl00$BodyContent$ContentPlaceHolder1$MainContentPlaceHolder$ResourceHostControl1$resContainer$rptContainers$ctl00$rptColumn1$ctl00$ctl01$Wrapper$lbxNodeProperty";
                string searchBtnId       = "ctl00_ctl00_ctl00_BodyContent_ContentPlaceHolder1_MainContentPlaceHolder_ResourceHostControl1_resContainer_rptContainers_ctl00_rptColumn1_ctl00_ctl01_Wrapper_btnSearch";

                chrome.Navigate().GoToUrl("https://solarwindscs.dell.com/Orion/SummaryView.aspx?ViewID=1");

                while (IsElementPresent(textboxName, false, true) == false)
                {
                    Thread.Sleep(25);
                }
                try
                {
                    OpenQA.Selenium.IWebElement searchBox           = chrome.FindElementByName(textboxName);
                    OpenQA.Selenium.IWebElement dropBox             = chrome.FindElementByName(attributeDropdown);
                    OpenQA.Selenium.IWebElement searchBtn           = chrome.FindElementById(searchBtnId);
                    OpenQA.Selenium.Support.UI.SelectElement select = new OpenQA.Selenium.Support.UI.SelectElement(dropBox);
                    //Console.WriteLine("HHHHHHH");
                    searchBox.SendKeys(valueToSearch);
                    //Console.WriteLine("HHHHHHH");
                    select.SelectByIndex(attributeIndex);
                    // Console.WriteLine("uyguygufuov");
                    searchBtn.Click();
                    // Console.WriteLine("HHHHHHH");

                    while (IsElementPresent("StatusMessage", true, false) == false)
                    {
                        Thread.Sleep(25);
                    }

                    string result = chrome.FindElementByClassName("StatusMessage").Text;
                    if (result.Contains("Nodes with ") && result.Contains(" similar to "))
                    {
                        ReadOnlyCollection <OpenQA.Selenium.IWebElement> amount = chrome.FindElementsByClassName("StatusIcon");
                        //Console.WriteLine(amount.Count);
                        handle.AddResult(row, valueToSearch, "Y", (amount.Count - 1).ToString());
                    }
                    else
                    {
                        handle.AddResult(row, valueToSearch, "N", "0");
                    }
                }
                catch (Exception e)
                {
                    throw new WebSearchException(Thread.CurrentThread.ManagedThreadId.ToString());
                }
            }
        }
Exemplo n.º 13
0
        // Select item na lista de forma automatica

        public void EscolherValorAleatorioNaLista(IWebElement elemento)
        {
            wait.Until(ExpectedConditions.ElementToBeClickable(elemento));

            Random random = new Random();

            OpenQA.Selenium.Support.UI.SelectElement selector = new OpenQA.Selenium.Support.UI.SelectElement(elemento);
            IList <IWebElement> options = selector.Options;
            int aux = options.Count;

            int r = random.Next(0, aux);

            new OpenQA.Selenium.Support.UI.SelectElement(elemento).SelectByText(options[r].Text.Trim());
        }
Exemplo n.º 14
0
        public bool selectByIndex(By locator, int index, string locatorName)
        {
            bool flag = false;

            try
            {
                Select s = new Select(driver.FindElement(locator));
                s.SelectByIndex(index);
                flag = true;
                return(flag);
            }
            catch (Exception)
            {
                return(flag);
            }
        }
Exemplo n.º 15
0
        public void incluirPergunta(string descricao)
        {
            selecionarMenuPergunta();



            driver.FindElement(By.Id("btnIncluir")).Click();
            driver.FindElement(By.Id("inputDescrTipoPergunta")).SendKeys(descricao);

            var combobox      = driver.FindElement(By.Id("dropStatus"));
            var selectElement = new OpenQA.Selenium.Support.UI.SelectElement(combobox);

            selectElement.SelectByText("Ativo");

            driver.FindElement(By.Id("btnSalvar")).Click();
            Thread.Sleep(1000);
        }
Exemplo n.º 16
0
        protected bool ReturnSelectByVisibleText(By locator, string text)
        {
            OpenQA.Selenium.Support.UI.SelectElement comboBox = new OpenQA.Selenium.Support.UI.SelectElement(WaitForElement(locator));

            IList <IWebElement> comboBoxList = comboBox.Options;

            foreach (var row in comboBoxList)
            {
                if (row.Text.Equals(text))
                {
                    return(true);
                }
            }

            return(false);

            ExtentReportHelpers.AddTestInfo(3, "PARAMETER: " + text);
        }
Exemplo n.º 17
0
        public void Logar(string usuario, string senha)
        {
            driver.FindElement(By.Id("txtLogin")).SendKeys(usuario);
            driver.FindElement(By.Id("txtSenha")).SendKeys(senha);
            driver.FindElement(By.Id("btnEnviar")).Click();


            var comboboxSistema      = driver.FindElement(By.Id("cmbSistemas"));
            var selectElementSistema = new OpenQA.Selenium.Support.UI.SelectElement(comboboxSistema);

            selectElementSistema.SelectByText("SISTEMA ELETRÔNICO DA OUVIDORIA");

            Thread.Sleep(1000);

            var comboboxOrgao      = driver.FindElement(By.Id("cmbOrgaos"));
            var selectElementOrgao = new OpenQA.Selenium.Support.UI.SelectElement(comboboxOrgao);

            selectElementOrgao.SelectByText("OUVID OUVIDORIA GERAL DO PODER JUDICIARIO");
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
 public SelectElement(IWebElement element, IWebDriver driver) : base(element, driver)
 {
     if (element.TagName == "select")
     {
         OldStyleSelect       = new OpenQA.Selenium.Support.UI.SelectElement(element);
         LazyAvailableOptions = new Lazy <IList <IWebElement> >(() => OldStyleSelect.Options);
         LazySelectedOptions  = new Lazy <IList <IWebElement> >(() => OldStyleSelect.AllSelectedOptions);
     }
     else
     {
         var listId = element.GetAttribute("list");
         LazyAvailableOptions = new Lazy <IList <IWebElement> >(() => driver.FindElements(By.XPath($"//datalist[@id='{listId}']/option")));
         LazySelectedOptions  = new Lazy <IList <IWebElement> >(() => new List <IWebElement>());
         var value = element.GetAttribute("value");
         if (!string.IsNullOrWhiteSpace(value))
         {
             SelectedOptions.Add(AvailableOptions.First(o => o.GetAttribute("value") == value));
         }
     }
 }
Exemplo n.º 20
0
        public bool selectByVisibleText(By locator, string visibletext, string locatorName)
        {
            bool flag = false;

            try
            {
                /*Highlight element*/

                WebElement         webElement = driver.FindElement(locator);
                JavascriptExecutor js         = driver as JavascriptExecutor;
                js.ExecuteScript("arguments[0].style.border='4px solid yellow'", webElement);
                /*Highlight code ends*/
                Select s = new Select(driver.FindElement(locator));
                s.SelectByText(visibletext);
                flag = true;
                return(flag);
            }
            catch (Exception)
            {
                return(flag);
            }
        }
Exemplo n.º 21
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();
        }
Exemplo n.º 22
0
 public SelectElement(By locator, string name) : base(locator, name)
 {
     WaitUntilDisplayed();
     _select = new UISelectElement(Element);
 }
Exemplo n.º 23
0
        public void ChromeTest()
        {
            using (var WebDriver = new ChromeDriver())
            {
                WebDriver.Manage().Window.Maximize();
                WebDriver.Navigate().GoToUrl(baseURL);

                var firstName = WebDriver.FindElementById("RESULT_TextField-2");
                firstName.SendKeys("Marco");

                var lastName = WebDriver.FindElementById("RESULT_TextField-3");
                lastName.SendKeys("Serrano");

                var address = WebDriver.FindElementById("RESULT_TextField-4");
                address.SendKeys("123 Street St.");

                var address2 = WebDriver.FindElementById("RESULT_TextField-5");
                address2.SendKeys("Apt 123");

                var city = WebDriver.FindElementById("RESULT_TextField-6");
                city.SendKeys("Townsville");

                var state         = WebDriver.FindElementById("RESULT_RadioButton-7");
                var selectElement = new OpenQA.Selenium.Support.UI.SelectElement(state);
                selectElement.SelectByText("Texas");

                var zipCode = WebDriver.FindElementById("RESULT_TextField-8");
                zipCode.SendKeys("77777");

                var phone = WebDriver.FindElementById("RESULT_TextField-9");
                phone.SendKeys("5557771234");

                var email = WebDriver.FindElementById("RESULT_TextField-10");
                email.SendKeys("*****@*****.**");

                OpenQA.Selenium.Interactions.Actions actions = new Actions(WebDriver);
                actions.MoveToElement(email);
                actions.Perform();

                var membership = WebDriver.FindElementByXPath("//div[@id='q16']/table/tbody/tr/td/label");
                membership.Click();
                membership = WebDriver.FindElementByXPath("//div[@id='q16']/table/tbody/tr/td[1]/label");
                membership.Click();
                membership = WebDriver.FindElementByXPath("//div[@id='q16']/table/tbody/tr/td[2]/label");
                membership.Click();

                var contact = WebDriver.FindElementByXPath("//div[@id='q21']/table/tbody/tr/td/label");
                contact.Click();
                contact = WebDriver.FindElementByXPath("//div[@id='q21']/table/tbody/tr/td[2]/label");
                contact.Click();
                contact = WebDriver.FindElementByXPath("//div[@id='q21']/table/tbody/tr/td[3]/label");            //contact.Click();
                contact.Click();

                var terms = WebDriver.FindElementByXPath("//div[@id='q30']/table/tbody/tr/td/label");
                terms.Click();

                var submit = WebDriver.FindElementById("FSsubmit");
                submit.Submit();

                Thread.Sleep(5000);

                WebDriver.Close();
            }
        }
Exemplo n.º 24
0
 public SelectElement(IWebDriver driver, IWebElement element, string fieldSelector)
     : base(driver, element, fieldSelector)
 {
     _element = new OpenQA.Selenium.Support.UI.SelectElement(element);
 }
Exemplo n.º 25
0
 protected void ComboBoxSelectByVisibleText(By locator, string text)
 {
     OpenQA.Selenium.Support.UI.SelectElement comboBox = new OpenQA.Selenium.Support.UI.SelectElement(WaitForElement(locator));
     comboBox.SelectByText(text);
     ExtentReportHelpers.AddTestInfo(3, "PARAMETER: " + text);
 }
Exemplo n.º 26
0
 public SelectElement(IWebDriver driver, IWebElement element, string fieldSelector)
     : base(driver, element, fieldSelector)
 {
     _element = new OpenQA.Selenium.Support.UI.SelectElement(element);
 }
Exemplo n.º 27
0
 protected void ComboBoxSelectByVisibleIndex(By locator, int location)
 {
     OpenQA.Selenium.Support.UI.SelectElement comboBox = new OpenQA.Selenium.Support.UI.SelectElement(WaitForElement(locator));
     comboBox.SelectByIndex(location);
     ExtentReportHelpers.AddTestInfo(3, "PARAMETER: " + location);
 }
Exemplo n.º 28
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();
        }
Exemplo n.º 29
0
 public SelectElement(By locator) : base(locator)
 {
     WaitUntilDisplayed();
     _select = new UISelectElement(Element);
 }