// Set value from drop down public static string SetDropDownValue(IWebDriver driver, string element, int index, string type) { if (type == "Id") { IWebElement el = driver.FindElement(By.Id(element)); SelectElement select = new SelectElement(el); select.SelectByIndex(index); return(select.ToString()); } if (type == "Name") { IWebElement el = driver.FindElement(By.Name(element)); SelectElement select = new SelectElement(el); select.SelectByIndex(index); return(select.ToString()); } if (type == "XPath") { IWebElement el = driver.FindElement(By.XPath(element)); SelectElement select = new SelectElement(el); select.SelectByIndex(index); return(select.ToString()); } else { return(String.Empty); } }
public bool langtest() { SelectElement lang1 = new SelectElement(driver.FindElement(By.XPath("//*[@id='ctl00_MainContentPlaceHolder_ddlLanguagePreferences']/option[2]"))); string language1 = lang1.ToString(); SelectElement lang2 = new SelectElement(driver.FindElement(By.XPath("//*[@id='ctl00_MainContentPlaceHolder_ddlLanguagePreferences']"))); string language2 = lang2.SelectedOption.ToString(); if (language2 == language1) { return(true); } else { return(false); } }
public bool test1() { //*[@id="ctl00_MainContentPlaceHolder_ddlTitle"] SelectElement element = new SelectElement(driver.FindElement(By.XPath("//*[@id='ctl00_MainContentPlaceHolder_ddlTitle']/option[4]"))); string title = element.ToString(); SelectElement element2 = new SelectElement(driver.FindElement(By.XPath(" //*[@id='ctl00_MainContentPlaceHolder_ddlTitle']"))); string title2 = element2.SelectedOption.ToString(); if (title2 == title) { return(true); } else { return(false); } }
public static bool SelectValuesCheckInTwoLists(this IWebElement element, IWebElement element2, string dropDownOption) { string optionsMissing = ""; SelectElement selectElement = new SelectElement(element); SelectElement selectElement2 = new SelectElement(element2); if (!selectElement.Options.Any()) { throw new Exception($"The following drop down options have no options {selectElement.ToString()} drop down"); } else if (selectElement.Options.Any(e => e.Text == dropDownOption) || selectElement2.Options.Any(e => e.Text == dropDownOption)) { return(true); } else { optionsMissing = dropDownOption.TrimEnd(','); throw new Exception($"The following drop down options are not present in the {element.TagName.ToString()} drop down: {optionsMissing.TrimEnd(',')}"); } }