diff --git a/src/WaitHelpers/ExpectedConditions.cs b/src/WaitHelpers/ExpectedConditions.cs index b007d75..d66e4d4 100644 --- a/src/WaitHelpers/ExpectedConditions.cs +++ b/src/WaitHelpers/ExpectedConditions.cs @@ -104,9 +104,9 @@ public static Func UrlMatches(string regex) /// /// The locator used to find the element. /// The once it is located. - public static Func ElementExists(By locator) + public static Func ElementExists(By locator) { - return (driver) => { return driver.FindElement(locator); }; + return (searchContext) => searchContext.FindElement(locator); } /// @@ -116,19 +116,19 @@ public static Func ElementExists(By locator) /// /// The locator used to find the element. /// The once it is located and visible. - public static Func ElementIsVisible(By locator) + public static Func ElementIsVisible(By locator) { - return (driver) => + return (searchContext) => + { + try { - try - { - return ElementIfVisible(driver.FindElement(locator)); - } - catch (StaleElementReferenceException) - { - return null; - } - }; + return ElementIfVisible(searchContext.FindElement(locator)); + } + catch (StaleElementReferenceException) + { + return null; + } + }; } /// @@ -138,13 +138,13 @@ public static Func ElementIsVisible(By locator) /// /// The locator used to find the element. /// The list of once it is located and visible. - public static Func> VisibilityOfAllElementsLocatedBy(By locator) + public static Func> VisibilityOfAllElementsLocatedBy(By locator) { - return (driver) => + return (searchContext) => { try { - var elements = driver.FindElements(locator); + var elements = searchContext.FindElements(locator); if (elements.Any(element => !element.Displayed)) { return null; @@ -166,9 +166,9 @@ public static Func> VisibilityOfAllE /// /// list of WebElements /// The list of once it is located and visible. - public static Func> VisibilityOfAllElementsLocatedBy(ReadOnlyCollection elements) + public static Func> VisibilityOfAllElementsLocatedBy(ReadOnlyCollection elements) { - return (driver) => + return (searchContext) => { try { @@ -192,13 +192,13 @@ public static Func> VisibilityOfAllE /// /// The locator used to find the element. /// The list of once it is located. - public static Func> PresenceOfAllElementsLocatedBy(By locator) + public static Func> PresenceOfAllElementsLocatedBy(By locator) { - return (driver) => + return (searchContext) => { try { - var elements = driver.FindElements(locator); + var elements = searchContext.FindElements(locator); return elements.Any() ? elements : null; } catch (StaleElementReferenceException) @@ -214,9 +214,9 @@ public static Func> PresenceOfAllEle /// The WebElement /// Text to be present in the element /// once the element contains the given text; otherwise, . - public static Func TextToBePresentInElement(IWebElement element, string text) + public static Func TextToBePresentInElement(IWebElement element, string text) { - return (driver) => + return (searchContext) => { try { @@ -236,13 +236,13 @@ public static Func TextToBePresentInElement(IWebElement elemen /// The locator used to find the element. /// Text to be present in the element /// once the element contains the given text; otherwise, . - public static Func TextToBePresentInElementLocated(By locator, string text) + public static Func TextToBePresentInElementLocated(By locator, string text) { - return (driver) => + return (searchContext) => { try { - var element = driver.FindElement(locator); + var element = searchContext.FindElement(locator); var elementText = element.Text; return elementText.Contains(text); } @@ -259,9 +259,9 @@ public static Func TextToBePresentInElementLocated(By locator, /// The WebElement /// Text to be present in the element /// once the element contains the given text; otherwise, . - public static Func TextToBePresentInElementValue(IWebElement element, string text) + public static Func TextToBePresentInElementValue(IWebElement element, string text) { - return (driver) => + return (searchContext) => { try { @@ -288,13 +288,13 @@ public static Func TextToBePresentInElementValue(IWebElement e /// The locator used to find the element. /// Text to be present in the element /// once the element contains the given text; otherwise, . - public static Func TextToBePresentInElementValue(By locator, string text) + public static Func TextToBePresentInElementValue(By locator, string text) { - return (driver) => + return (searchContext) => { try { - var element = driver.FindElement(locator); + var element = searchContext.FindElement(locator); var elementValue = element.GetAttribute("value"); if (elementValue != null) { @@ -362,13 +362,13 @@ public static Func FrameToBeAvailableAndSwitchToIt(By lo /// /// The locator used to find the element. /// if the element is not displayed; otherwise, . - public static Func InvisibilityOfElementLocated(By locator) + public static Func InvisibilityOfElementLocated(By locator) { - return (driver) => + return (searchContext) => { try { - var element = driver.FindElement(locator); + var element = searchContext.FindElement(locator); return !element.Displayed; } catch (NoSuchElementException) @@ -392,13 +392,13 @@ public static Func InvisibilityOfElementLocated(By locator) /// The locator used to find the element. /// Text of the element /// if the element is not displayed; otherwise, . - public static Func InvisibilityOfElementWithText(By locator, string text) + public static Func InvisibilityOfElementWithText(By locator, string text) { - return (driver) => + return (searchContext) => { try { - var element = driver.FindElement(locator); + var element = searchContext.FindElement(locator); var elementText = element.Text; if (string.IsNullOrEmpty(elementText)) { @@ -428,11 +428,11 @@ public static Func InvisibilityOfElementWithText(By locator, s /// /// The locator used to find the element. /// The once it is located and clickable (visible and enabled). - public static Func ElementToBeClickable(By locator) + public static Func ElementToBeClickable(By locator) { - return (driver) => + return (searchContext) => { - var element = ElementIfVisible(driver.FindElement(locator)); + var element = ElementIfVisible(searchContext.FindElement(locator)); try { if (element != null && element.Enabled) @@ -457,9 +457,9 @@ public static Func ElementToBeClickable(By locator) /// /// The element. /// The once it is clickable (visible and enabled). - public static Func ElementToBeClickable(IWebElement element) + public static Func ElementToBeClickable(IWebElement element) { - return (driver) => + return (searchContext) => { try { @@ -484,9 +484,9 @@ public static Func ElementToBeClickable(IWebElement ele /// /// The element. /// is the element is still attached to the DOM; otherwise, . - public static Func StalenessOf(IWebElement element) + public static Func StalenessOf(IWebElement element) { - return (driver) => + return (searchContext) => { try { @@ -505,7 +505,7 @@ public static Func StalenessOf(IWebElement element) /// /// The element. /// given element is selected.; otherwise, . - public static Func ElementToBeSelected(IWebElement element) + public static Func ElementToBeSelected(IWebElement element) { return ElementSelectionStateToBe(element, true); } @@ -516,9 +516,9 @@ public static Func ElementToBeSelected(IWebElement element) /// The element. /// selected or not selected /// given element is in correct state.; otherwise, . - public static Func ElementToBeSelected(IWebElement element, bool selected) + public static Func ElementToBeSelected(IWebElement element, bool selected) { - return (driver) => + return (searchContext) => { return element.Selected == selected; }; @@ -530,9 +530,9 @@ public static Func ElementToBeSelected(IWebElement element, bo /// The element. /// selected or not selected /// given element is in correct state.; otherwise, . - public static Func ElementSelectionStateToBe(IWebElement element, bool selected) + public static Func ElementSelectionStateToBe(IWebElement element, bool selected) { - return (driver) => + return (webElement) => { return element.Selected == selected; }; @@ -543,7 +543,7 @@ public static Func ElementSelectionStateToBe(IWebElement eleme /// /// The locator used to find the element. /// given element is selected.; otherwise, . - public static Func ElementToBeSelected(By locator) + public static Func ElementToBeSelected(By locator) { return ElementSelectionStateToBe(locator, true); } @@ -554,13 +554,13 @@ public static Func ElementToBeSelected(By locator) /// The locator used to find the element. /// selected or not selected /// given element is in correct state.; otherwise, . - public static Func ElementSelectionStateToBe(By locator, bool selected) + public static Func ElementSelectionStateToBe(By locator, bool selected) { - return (driver) => + return (searchContext) => { try { - var element = driver.FindElement(locator); + var element = searchContext.FindElement(locator); return element.Selected == selected; } catch (StaleElementReferenceException)