Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99418

How to correctly wait in POM using Selenium C#

$
0
0

I have setup some explicit waits for various things in my tests but have had to specify strings for my XPaths, ids etc. So my page setups include things like...

public const string ApplyDatasetButton_XPath = "//*[@id='btn_apply_datasets']";
[FindsBy(How = How.XPath, Using = ApplyDatasetButton_XPath)]
public IWebElement ApplyDatasetButton { get; set; }

...and then I am using this in my test in the wait like...

SeleniumGetMethods.WaitForElementVisible(By.XPath(ApplyDatasetButton_XPath), 20);

...where the wait is setup as...

public static void WaitForElementVisible(By element, int timeoutInSeconds)
    {
        if (timeoutInSeconds > 0)
        {
            WebDriverWait wait = new WebDriverWait(DriverSetup.driver, TimeSpan.FromSeconds(timeoutInSeconds));
            wait.Until(ExpectedConditions.ElementIsVisible(element));
        }
    }

However creating the string seems overkill but I couldn't figure out how to just use the element created. Basically is there a way in C# to do something like...

[FindsBy(How = How.XPath, Using = "//*[@id='btn_apply_datasets']")]
public IWebElement ApplyDatasetButton { get; set; }

SeleniumGetMethods.WaitForElementVisible(ApplyDatasetButton, 20);

Viewing all articles
Browse latest Browse all 99418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>