How to use page object with elements that are not yet visible

i want to use the page object like in this example 

[FindsBy(How = How.Id, Using = “log”)]
 public IWebElement UserName { get; set; }

The problem in this design that the web elements are initialized in the constructor so if i have a search page then the web elements will be visible after i search on them.Is  there another way so that the web elements are not initialized in he constructor or should i define only the By objects as properties and create a method to get the web element 

Add Comment
1 Answer(s)


There are many ways that you can handle this. However, when we create a an element using PageFactory then only a proxy element is created. This means that you don’t have to worry about the actual existence of element. Once you perform some action on the element, for e.g. element.Click then proxy element is resolved to actual element. If at this point the element is not present on webpage, you will get NoSuchElementException.


Virender Singh Professor Answered on June 13, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.