public void SelectValue(string value) { WaitForElementPresent(); var select = new UISelectElement(GetElement()); select.SelectByText(value); }
/// <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); }
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)); }
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(); }
/// <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); }
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); }
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); }
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"); }
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); } }
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(); }
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); }
public void SelectValue(string value) { WaitUntilDisplayed(); _select.SelectByText(value); }
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(); } }
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(); }