public void SelectByValue(string value, SelectByValueType strict = SelectByValueType.Equal) { IWebElement listDropDown = _driver.FindElement(_listDropDownId); IWebElement firstElement = _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[1]")); IWebElement lastElement = _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[last()]")); Point fistElementStart = firstElement.Location; Point lastElementStart = lastElement.Location; //_driver.FindElement(_arrowId).FindElement(By.XPath("./parent::*")).Click(); _driver.FindElement(_arrowId).Click(); BasePage.WaitTillStopMoving(_driver, firstElement, fistElementStart); BasePage.WaitTillStopMoving(_driver, lastElement, lastElementStart); fistElementStart = firstElement.Location; lastElementStart = lastElement.Location; if (strict == SelectByValueType.Equal) { _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[text() = '" + value + "']")). ScrollIntoView(). Click(); } else if (strict == SelectByValueType.Contains) { _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[contains(text(), '" + value + "')]")).ScrollIntoView(). Click(); } else { throw new Exception("Wrong SelectByValueType"); } try { BasePage.WaitTillStopMoving(_driver, firstElement, fistElementStart); BasePage.WaitTillStopMoving(_driver, lastElement, lastElementStart); } catch (StaleElementReferenceException) { Trace.WriteLine(BasePage.TraceLevelElement + "StaleElementReferenceException in SelectByValue of '" + value + "'"); } }
public void SelectByValue(string value, SelectByValueType strict = SelectByValueType.Equal) { IWebElement listDropDown = _driver.FindElement(_listDropDownId); IWebElement firstElement = _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[1]")); IWebElement lastElement = _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[last()]")); Point fistElementStart = firstElement.Location; Point lastElementStart = lastElement.Location; //_driver.FindElement(_arrowId).FindElement(By.XPath("./parent::*")).Click(); _driver.FindElement(_arrowId).Click(); BasePage.WaitTillStopMoving(_driver, firstElement, fistElementStart); BasePage.WaitTillStopMoving(_driver, lastElement, lastElementStart); fistElementStart = firstElement.Location; lastElementStart = lastElement.Location; if (strict == SelectByValueType.Equal) { _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[text() = '" + value + "']")). Click(); } else if (strict == SelectByValueType.Contains) { _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[contains(text(), '" + value + "')]")). Click(); } else { throw new Exception("Wrong SelectByValueType"); } try { BasePage.WaitTillStopMoving(_driver, firstElement, fistElementStart); BasePage.WaitTillStopMoving(_driver, lastElement, lastElementStart); } catch (StaleElementReferenceException) { Trace.WriteLine(BasePage.TraceLevelElement + "StaleElementReferenceException in SelectByValue of '" + value + "'"); } }
public static void SelectByValue (IWebDriver driver, By arrowId, By listDropDownId, string value, SelectByValueType strict = SelectByValueType.Equal) { Trace.WriteLine(BasePage.TraceLevelElement + "Select '" + value + "' in the list '" + listDropDownId + "'"); new SlidingSelect(driver, arrowId, listDropDownId).SelectByValue(value, strict); }
public static void SelectByValue(IWebDriver driver, By arrowId, By listDropDownId, string value, SelectByValueType strict = SelectByValueType.Equal) { Trace.WriteLine(BasePage.TraceLevelElement + "Select '" + value + "' in the list '" + listDropDownId + "'"); new SlidingSelect(driver, arrowId, listDropDownId).SelectByValue(value, strict); }