public static void WaitForAjaxSelectElementPopulated(this IWebDriver driver, By bySelectElement, double timeoutSeconds) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutSeconds)); wait.Until(x => { try { SelectElement selectElement = new SelectElement(driver.AjaxFind(bySelectElement, timeoutSeconds)); return(selectElement.Options.Any()); } catch (StaleElementReferenceException) { return(false); } }); }
public static void WaitForAjaxSelectElementPopulatedWithElementText(this IWebDriver driver, By bySelectElement, string text, double timeoutSeconds) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutSeconds)); wait.Until(x => { try { SelectElement selectElement = new SelectElement(driver.AjaxFind(bySelectElement, timeoutSeconds)); var element = selectElement.Options.Where(y => y.Text == text).FirstOrDefault(); return(element != null); } catch (StaleElementReferenceException) { return(false); } }); }
public void GivenIHaveEnteredSomethingIntoTheSearch(int zip, int category, int subCategory) { //Navigate to the site driver.Navigate().GoToUrl(WeNeedUHaveUrls.Home); // Find the text input element by its name IWebElement query = driver.FindElement(By.Name("ZipCode")); // Enter something to search for query.SendKeys(zip.ToString()); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3000)); wait.Until(x => { try { SelectElement selectElement = new SelectElement(driver.AjaxFind(By.Id("Category"), 3000)); return(selectElement.Options.Count > 1); } catch (StaleElementReferenceException) { return(false); } }); IWebElement dropDownListBox = driver.FindElement(By.Id("Category")); SelectElement clickThis = new SelectElement(dropDownListBox); clickThis.SelectByIndex(category); IWebElement dropDownListBox2 = driver.FindElement(By.Id("SubCategory")); SelectElement clickThis2 = new SelectElement(dropDownListBox2); clickThis2.SelectByIndex(subCategory); // Now submit the form query.Submit(); }