Hi Selenium experts,
I have created a simple page object model and initialized using PageFactory class.
Code is able to perform actions on the element, but if we retrieve properties (like Text on IWebElement), below error is thrown.
"Cannot obtain fields or call methods on the instance of type 'OpenQA.Selenium.IWebElement' because it is a proxy to a remote object."
Code:
public class AuditBlade
{
[FindsBy(How = How.CssSelector, Using = "input[type='email'][name='user']")]
public IWebElement EltUser;
public AuditBlade(IWebDriver driver)
{
PageFactory.InitElements(driver, this);
}
public void FillData(string aName)
{
EltUser.Clear();
EltUser.SendKeys(aName); //This is working fine. It is able to set the data to a text box. Even other controls are working fine if we are performing actions on them, instead of reading values.
//Do some other stuff.
Log(EltUser.Text); //Here 'Text' is coming as blank. When debugged, an exception is thrown with the message as above.
}
}
If this is the case, then I can not use the properties with the [FindsBy] attribute/notation. I will have to create properties myself (get) and return with the statements driver.FindElementBy. Then what will be the use of this Page Object Model or PageFactory?
Surprisingly, if the code can set values on a control, why cant we read values of that control? Appreciate your guidance on this.
Browser: Chrome
Implementation: WebDriver with PageObjectModel, C#
Thanks,
Praveen