I'm using the PageObjectModel as I'm understanding it. The FindsBy elements are instantiated by the PageFactory (in the constructor)
public class wizard_Uittreksel_Bestemmeling
{
private readonly IWebDriver _driver;
[FindsBy(How = How.CssSelector, Using = "input[name=\"OntvangstTypeCoid\"][value=\"Permail\"]")]
private IWebElement radio_ontvangenPerMail;
[FindsBy(How = How.CssSelector, Using = "input[name=\"OntvangstTypeCoid\"][value=\"Perbrief\"]")]
private IWebElement radio_ontvangenPerBrief;
[FindsBy(How = How.Id, Using = "Email")]
private IWebElement txt_email;
Now, this is working fine. However, for these elements I sometimes need
- their XPath, e.g. for finding dynamic elements in the same containing DIV
- their ID or CssSelector, e.g. to determine if the element exists, using driver.FindElement(By.Locator())
As there's no way to extract these locator values from the IWebElement, I wonder if anyone else has had this issue? What would be the cleanest way to solve this issue?
WebElement
and use the WebElement'sfindElement()
method. If you need to determine if an element exists, just call the WebElement'sisDisplayed()
method.