Page object model: Error: Cannot obtain fields or call methods on the instance of type 'OpenQA.Selen

660 views
Skip to first unread message

Praveen P

unread,
Sep 23, 2015, 6:32:46 PM9/23/15
to Selenium Users
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
       

MWQA

unread,
Sep 24, 2015, 7:20:22 AM9/24/15
to Selenium Users
@FindsBy should be @FindBy ? Looks like a typo to me

Praveen P

unread,
Sep 24, 2015, 1:37:35 PM9/24/15
to Selenium Users
FindsBy is the correct attribute in C#. 
As already mentioned, the code is working absolutely fine in performing actions on them like SendKeys but not able to read values like x.Text. So, the question is "is this a limitation if we use this pattern of decorating elements with FindBy and using PageFactory.InitElements..."

Thanks,
Praveen

Subroto Biswas

unread,
Jan 17, 2018, 8:59:07 PM1/17/18
to Selenium Users
I know its a old thread but i stumbled across this error today. Where you able to find the solution ?
Reply all
Reply to author
Forward
0 new messages