How to convert IWebElement in Locator Selenium WebDriver Page Objects?
I work like this:
using OpenQA.Selenium.Support.PageObjects;
[FindsBy(How = How.Id, Using = "user")]
public IWebElement txtUser { get; set; }
public void fillUserField(string user)
{
wait.Until(ExpectedConditions.ElementIsVisible(By.Id("user")));
txtUser.SendKeys(user);
}
I do not want to repeat the ID "user" in wait.
I don't work like this:
public void fillUserField(string user)
{ // TO DO - Convert IWebElement in Locator (BY)
//Argument1: Cannot convert from 'OpenQA.Selenium.IWebElement' to 'OpenQA.Selenium.By'
wait.Until(ExpectedConditions.**ElementIsVisible(txtUser)**);
txtUser.SendKeys(user);
}
Is possible? Thanks!
You would declare a locator at the top of the class.
public By userLocator = By.Id("user");
and then use it like
wait.Until(ExpectedConditions.ElementIsVisible(userLocator));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.