When I navigate to my page under test, at the beginning of the entire Page Object class initialization certain elements are not visible, but they become visible when I click on drop down (which is not a select drop down).

I search for those invisible elements with the [FindsBy] annotation at the top of the class, but when it comes to interact with them, driver can't locate. I know I can use driver.FindElement(), but would like to stick with the page object design principles.

Is there any ways to tell Page Object to search for an element again? Any help will be appreciated.

1 Answer 1


The page object will search for the element every time you try to interact with it unless you've used the [CachedLookup] attribute, e.g.,

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

Here CachedLogOut will only be located the first time you interact with it. If you don't use [CachedLookup] then the element will be searched for every time you interact with it:

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

Here LogOut will be searched for every time you call one of its methods etc.

I can think of two ways to deal with your scenario:

1) Design your methods for interacting with the WebElements in the menu something like this:

  1. Check if the menu is open
  2. If it's not open, open it
  3. Wait for the element you want to interact with using an Explicit Wait
  4. Interact with the element
  5. Return the Page Object (if it makes sense to do so)

2) If the menu is something that is available on more than one page then it might be worth considering creating a separate page object for that menu, which is totally acceptable as far as page object design principles go. Then use method 1) above in this separate page object.

The Explicit Wait is how you ask your code to located the element again (and again and again...) until it has either been found or a set time has expired. The following will keep checking for LogOut to be clickable until timeout seconds have expired. If LogOut isn't clickable by then it will throw an exception.

new WebDriverWait(Web.Driver, TimeSpan.FromSeconds(timeout))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.