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);