What is the appetite for having ExpectedCondition methods that take IWebElement and not just locator?

15 views
Skip to first unread message

flapmio 2

unread,
Jul 10, 2017, 9:30:39 PM7/10/17
to webdriver
Hi,

I am using the Page Object Model and have classes where I have defined my Elements.
I also use Webdriver waits with the .Until --> ExpectedConditions class to check the condition of an element.

As I have already defined my element in a POM class most of the ExpectedConditions methods are not fit for my purpose anymore.

Can we have "equivalent" methods that take IWebElement instead of a locator?

For Example:

        /// <summary>
        /// An expectation for checking that an element is either invisible or not present on the DOM.
        /// </summary>
        /// <<param name="element">The element.</param>
        /// <returns><see langword="true"/> if the element is not displayed; otherwise, <see langword="false"/>.</returns>
        public static Func<IWebDriver, bool> InvisibilityOfElement(IWebElement element)
        {
            return (driver) =>
            {
                try
                {
                    if (!element.Displayed)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch (NoSuchElementException)
                {
                    // Returns true because the element is not present in DOM. The
                    // try block checks if the element is present but is invisible.
                    return true;
                }
                catch (StaleElementReferenceException)
                {
                    // Returns true because stale element reference implies that element
                    // is no longer visible.
                    return true;
                }
            };
     }


Thanks
Reply all
Reply to author
Forward
0 new messages