protected static bool IsElementVisible(PageElement pageElement, TimeSpan?maxWaitTime = null) { pageElement.GoToFrame(); return(SeleniumUtility .WebDriverWait(ExpectedConditions.ElementIsVisible(pageElement.Locator), maxWaitTime ?? Default5Seconds) .Displayed); }
protected static void Click(PageElement pageElement, TimeSpan?maxWaitTime = null) { pageElement.GoToFrame(); SeleniumUtility .WebDriverWait( ExpectedConditions.ElementToBeClickable(SeleniumDriver.Driver.FindElement(pageElement.Locator)), maxWaitTime).Click(); }
protected static void RightClick(PageElement pageElement, TimeSpan?maxWaitTime = null) { pageElement.GoToFrame(); var actions = new OpenQA.Selenium.Interactions.Actions(SeleniumDriver.Driver); actions.ContextClick(SeleniumUtility.WebDriverWait(ExpectedConditions.ElementIsVisible(pageElement.Locator), maxWaitTime ?? Default5Seconds)).Build().Perform(); }
protected static void ClickMultipleElements(PageElement pageElement) { pageElement.GoToFrame(); foreach (var element in SeleniumDriver.Driver.FindElements(pageElement.Locator)) { SeleniumUtility.WebDriverWait(ExpectedConditions.ElementToBeClickable(element), Default5Seconds) .Click(); } }
protected static void DoubleClick(PageElement pageElement, TimeSpan?maxWaitTime = null) { if (IsElementVisible(pageElement, maxWaitTime ?? Default5Seconds)) { pageElement.GoToFrame(); new OpenQA.Selenium.Interactions.Actions(SeleniumDriver.Driver) .DoubleClick(SeleniumDriver.Driver.FindElement(pageElement.Locator)).Build() .Perform(); } }
protected static void ClickAndHold(PageElement pageElement, TimeSpan?maxWaitTime = null) { pageElement.GoToFrame(); var actions = new OpenQA.Selenium.Interactions.Actions(SeleniumDriver.Driver); var onElement = SeleniumDriver.Driver.FindElement(pageElement.Locator); actions.ClickAndHold(onElement).Build().Perform(); Thread.Sleep(maxWaitTime ?? Default5Seconds); actions.Release(onElement).Build().Perform(); }
protected static void Type(PageElement pageElement, string input) { pageElement.GoToFrame(); var element = SeleniumUtility.WebDriverWait(ExpectedConditions.ElementToBeClickable(pageElement.Locator)); element.Clear(); element.SendKeys(input);// Assert.AreEqual(input, ExtractText(pageElement, Default5Seconds)); }
protected static void SendKeys(PageElement pageElement, params string[] keys) { var actions = new OpenQA.Selenium.Interactions.Actions(SeleniumDriver.Driver); foreach (var key in keys) { pageElement.GoToFrame(); actions.SendKeys(SeleniumDriver.Driver.FindElement(pageElement.Locator), key).Build().Perform(); Thread.Sleep(1000); } }
protected static void SelectDropDownByValue(PageElement pageElement, string value) { pageElement.GoToFrame(); var dropdown = new SelectElement(SeleniumDriver.Driver.FindElement(pageElement.Locator)); dropdown.SelectByValue(value); var dropdownValue = dropdown.AllSelectedOptions.First(e => e.Selected).GetAttribute("value"); if (!dropdownValue.Equals(value, StringComparison.CurrentCultureIgnoreCase)) { throw new ValueNotSelectedException($"Dropdown was not set to value: {dropdownValue}"); } }
protected static void SelectDropDownByVisibleText(PageElement pageElement, string visibleText) { pageElement.GoToFrame(); var dropdown = new SelectElement(SeleniumDriver.Driver.FindElement(pageElement.Locator)); dropdown.SelectByText(visibleText); var dropdownText = dropdown.AllSelectedOptions.First(e => e.Selected).Text; if (!dropdownText.Equals(visibleText)) { throw new ValueNotSelectedException($"Dropdown was not set to value: {dropdownText}"); } }
protected static string ExtractText(PageElement pageElement, TimeSpan?maxWaitTime) { try { pageElement.GoToFrame(); var element = SeleniumUtility.WebDriverWait( ExpectedConditions.ElementIsVisible(pageElement.Locator), maxWaitTime ?? Default5Seconds); var text = GetTextByType(pageElement.ElementType, element); if (text == null) { throw new NotFoundException($"{TextNotFound} Element: {pageElement}"); } return(text); } catch (Exception e) { throw new NotFoundException($"Error getting value: {e.StackTrace}"); } }
protected static bool IsElementNotVisible(PageElement pageElement, TimeSpan?maxWaitTime = null) { pageElement.GoToFrame(); return(SeleniumUtility.WebDriverWait(ExpectedConditions.InvisibilityOfElementLocated(pageElement.Locator), maxWaitTime ?? Default5Seconds)); }