/// <summary> /// Enters `text` into a text box. /// </summary> /// <param name="how"></param> /// <param name="elementName"></param> /// <param name="text"></param> public void EnterText(ElementAccessorType how, string elementName, string text) { By findBy = FindElementBy(how, elementName); this._driver.FindElement(findBy).Clear(); this._driver.FindElement(findBy).SendKeys(text); }
/// <summary> /// Get Web Element based on Selenium accessor type. /// </summary> /// <param name="how"></param> /// <param name="elementName"></param> /// <returns>By</returns> public By FindElementBy(ElementAccessorType how, string elementName) { By findBy = null; switch (how) { case ElementAccessorType.ID: findBy = By.Id(elementName); break; case ElementAccessorType.ClassName: findBy = By.ClassName(elementName); break; case ElementAccessorType.XPath: findBy = By.XPath(elementName); break; default: findBy = By.Id(elementName); break; } return(findBy); }
/// <summary> /// Get the displayed text /// </summary> /// <param name="how"></param> /// <param name="element"></param> /// <returns>String</returns> public string GetText(ElementAccessorType how, string element) { By findBy = FindElementBy(how, element); string text = this._driver.FindElement(findBy).Text; return(text); }
/// <summary> /// Check if element is present on page or not /// </summary> /// <param name="how"></param> /// <param name="elementName"></param> /// <returns></returns> public bool IsElementPresent(ElementAccessorType how, string elementName) { By findBy = FindElementBy(how, elementName); // Note: FindElement throws an exception if it cannot find element. This is handled in DriverUtilitiesValidation return(_driver.FindElement(findBy).Displayed); }
/// <summary> /// Sets an explicit wait time in seconds. /// </summary> /// <param name="driver"></param> /// <param name="seconds"></param> /// <param name="elementName"></param> public void ExplicitWait(ElementAccessorType how, string elementName, double seconds) { WebDriverWait wait = new WebDriverWait(this._driver, TimeSpan.FromSeconds(seconds)); By findBy = FindElementBy(how, elementName); wait.Until(drv => drv.FindElement(findBy)); }
/// <summary> /// Clicks on an element. /// </summary> /// <param name="how"></param> /// <param name="elementName"></param> public void Click(ElementAccessorType how, string elementName) { By findBy = FindElementBy(how, elementName); // ExplicitWait(_driver, elementName); this._driver.FindElement(findBy).Click(); }