/// <summary> /// Reduce the verbosity of the code used for creating locators by using this unified method /// </summary> /// <param name="LocateBy"></param> /// <param name="ByLocatorString"></param> /// <returns></returns> public By ByElementLocator(LocateBy LocatedBy, string ByLocatorString) { //Reset to a null object to remove any garbage ByElement = null; if (!string.IsNullOrEmpty(ByLocatorString)) { switch (LocatedBy) { case LocateBy.Id: ByElement = By.Id(ByLocatorString); break; case LocateBy.Name: ByElement = By.Name(ByLocatorString); break; case LocateBy.XPath: ByElement = By.XPath(ByLocatorString); break; case LocateBy.CssSelector: ByElement = By.CssSelector(ByLocatorString); break; case LocateBy.TagName: ByElement = By.TagName(ByLocatorString); break; case LocateBy.LinkText: ByElement = By.LinkText(ByLocatorString); break; default: throw new ArgumentException(); } //end switch } //endif: there's a locator value return(ByElement); }//end method ByElementLocator
public RadioButton(string locator, LocateBy locatorType) : base(locator, locatorType) { }
public Clickable(string locator, LocateBy locatorType) : base(locator, locatorType) { }
/// <summary> /// Click on an element without any wait. /// </summary> /// <param name="locator"></param> /// <param name="locateBy"></param> public void Click(string locator, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); driver.FindElement(by).Click(); }
public void VerifyElementPresent(string locator, bool expected, LocateBy locateBy) { bool actual = this.IsElementPresent(locator, locateBy); if (actual != expected) { this.FailTest(string.Format("Element '{0}' is{1} present!", locator, (expected ? " NOT" : string.Empty))); } }
public void SelectWithIndex(string locator, int index, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); this.WaitForElementPresent(by); IWebElement select = driver.FindElement(by); SelectElement item = new SelectElement(select); item.SelectByIndex(index); }
public void SendKeys(string locator, object value, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); driver.FindElement(by).SendKeys(Convert.ToString(value)); }
public int GetElementsCount(string locator, LocateBy LocatorType) { return this.GetElements(locator, LocatorType).Count; }
public string GetId(string locator, LocateBy locateBy) { return this.GetAttribute(locator, "id", locateBy); }
public string GetAttribute(string locator, string attribute, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); this.WaitForElementPresent(by); try { return driver.FindElement(by).GetAttribute(attribute); } catch { this.FailTest("Failed to get attribute '" + attribute + "' for element: " + by.ToString()); return string.Empty; } }
public List<IWebElement> GetElements(string locator, LocateBy LocatorType) { ReadOnlyCollection<IWebElement> elements = this.driver.FindElements(this.GetLocatorFinder(locator, LocatorType)); List<IWebElement> elementList = new List<IWebElement>(); foreach (IWebElement element in elements) { elementList.Add(element); } return elementList; }
private By GetLocatorFinder(string locator, LocateBy locateBy) { switch (locateBy) { case LocateBy.XPath: return By.XPath(locator); case LocateBy.Id: return By.Id(locator); case LocateBy.LinkText: return By.LinkText(locator); case LocateBy.PartialLinkText: return By.PartialLinkText(locator); case LocateBy.CssSelector: return By.CssSelector(locator); case LocateBy.ClassName: return By.ClassName(locator); case LocateBy.Name: return By.Name(locator); case LocateBy.TagName: return By.TagName(locator); default: this.FailTest(string.Format("Cannot determine locator finder type for '{0}' located by '{1}'", locator, locateBy.ToString())); return null; } }
public void WaitForElementPresent(string locator, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); this.WaitForElementPresent(by); }
public void WaitForDisplayAndClick(string locator, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); IWebElement element = this.WaitForElementDisplay(by); element.Click(); }
public Label(string locator, LocateBy locatorType) : base(locator, locatorType) { }
public string GetSelectedLabel(string locator, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); this.WaitForElementPresent(by); IWebElement select = driver.FindElement(by); SelectElement item = new SelectElement(select); select = item.SelectedOption; return select.Text; }
public bool IsOptionExistInSelect(string locator, object value, LocateBy locateBy) { bool ret = false; By by = this.GetLocatorFinder(locator, locateBy); this.WaitForElementPresent(by); IWebElement select = driver.FindElement(by); SelectElement item = new SelectElement(select); string val = Convert.ToString(value); try { item.SelectByText(val); ret = true; } catch { ret = false; } return ret; }
public string GetText(string locator, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); this.WaitForElementPresent(by); return driver.FindElement(by).Text; }
public void SelectWithValue(string locator, string value, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); this.WaitForElementPresent(by); IWebElement select = driver.FindElement(by); SelectElement item = new SelectElement(select); string val = Convert.ToString(value); item.SelectByValue(val); }
public string GetValue(string locator, LocateBy locateBy) { return this.GetAttribute(locator, "value", locateBy); }
public void SetCheckbox(string locator, bool check, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); IWebElement element = this.WaitForElementDisplay(by); if (check) { if (!element.Selected) { element.Click(); } } else { if (element.Selected) { element.Click(); } } }
public bool IsChecked(string locator, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); this.WaitForElementPresent(by); return driver.FindElement(by).Selected; }
public void Type(string locator, object value, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); IWebElement element = this.WaitForElementDisplay(by); try { element.Clear(); } catch { // Ignore exception such as: // 'Element must be user-editable in order to clear' } element.SendKeys(Convert.ToString(value)); }
public bool IsEditable(string locator, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); this.WaitForElementPresent(by); return driver.FindElement(by).Enabled; }
public Element(LocateBy ByMethod, string LocatorValue = "") { ByElement = ByElementLocator(ByMethod, LocatorValue); LocatorString = LocatorValue; LocatedBy = ByMethod; }
public bool IsElementDisplay(string locator, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); IWebElement element; try { element = driver.FindElement(by); } catch (NoSuchElementException) { return false; } return element.Displayed; }
public CheckBox(string locator, LocateBy locatorType) : base(locator, locatorType) { }
/// <summary> /// Determine whether a element is hidden using its style attibute. /// "display: none;" = not hidden /// "display: block;" = hidden /// </summary> /// <param name="locator"></param> /// <returns></returns> public bool IsElementHidden(string locator, LocateBy locateBy) { string styleAttributeText = string.Empty; string classAttributeText = string.Empty; try { styleAttributeText = GetAttribute(locator, "style", locateBy); } catch { styleAttributeText = string.Empty; } try { classAttributeText = GetAttribute(locator, "class", locateBy); } catch { classAttributeText = string.Empty; } if (styleAttributeText.Contains("display: none;") || styleAttributeText.Contains("display:none;") || classAttributeText.Contains("hidden")) { return true; } else if (styleAttributeText.Contains("display: block;") || styleAttributeText.Contains("display:block;")) { return false; } else { return !IsElementPresent(locator, locateBy); } }
public Input(string locator, LocateBy locatorType) : base(locator, locatorType) { }
public bool IsElementPresent(string locator, LocateBy locateBy) { By by = this.GetLocatorFinder(locator, locateBy); try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } }
public MultiChoiceDropdown(string locator, LocateBy locatorType) : base(locator, locatorType) { this.GetOptions(); }
public ElementBase(string locator, LocateBy locatorType) { Locator = locator; TypeOfLocator = locatorType; }