I'm using page factory and need to explicitly wait until particulate elements load. Please advise how to do that. up to now I have following..

public class HomePage {
final WebDriver driver;
WebDriverWait wait;

@FindBy(xpath = "//*[contains(@id,'ctl00_LeftPanel_LeftNavigationMenu_nbMenu_GHE')]")
List<WebElement> Navi_Elements ;

and my constructor looks like

public  HomePage(WebDriver driver){
        this.driver = driver;
        wait = new WebDriverWait(driver,45);

now I'm trying to do in my method (in home page class) is.... something like...

    public void clickNavigator(String sMyNode){
                try{ wait.until(ExpectedConditions.presenceOfAllElements(Navi_Elements));

But in ExpectedConditions class there is no method to check presence which accepts Element/s

But according to This question it can be done

can not use "visibilityOfAllElements" since there is no visibility attribute in element

I'm using selenium 3.11

2 Answers 2


Page factory creates pages. How do you create elements?

Element factory is one way to create elements.

Once created, you use that instance and wait for any condition. Waiting is ignorant (and not interested) about the way you created the element.

Of course in a strictly typed language like Java you need to be careful about the types.

What are your Java OOP skills? If your skills are not on par, maybe you should avoid factories and just copy-paste some code? Follow some tutorials?

  • You are correct my Java OOP skills are beginner level. that's why I'm asking this question. So what you are telling me is it is impossible to define wait condition in my home page class? if possible could you please direct me to how....yes even good tutorial would be fine.
    – 1234
    Commented Apr 22, 2018 at 23:44
  • @Studeera - you can define whatever you want wherever you want. And deal with the consequences of course :-) I would suggest to spend more time following free tutorials on Java itself, and on OOP design. Only after you master the basics, dive deeper into Selenium. "Head-first" series of books by Kathy Sierra are excellent intro books (Java, OOP etc). Commented Apr 23, 2018 at 2:21
  • Also, Python is much easier language to learn than Java as is widely considered as best first language. In fact, if you do not have any Java guru around and just self-learning, Python will get you into programming much faster, IMHO. Google for "free online course of X" Commented Apr 23, 2018 at 2:22
  • Thanks ...I'm already in Python and comfy with it. Selecting java is to use TestNG where python unit test is useless for functionality testing. I found answer to my question in [this link] (stackoverflow.com/questions/9938986/…)
    – 1234
    Commented Apr 23, 2018 at 4:15
  • @Studeera - I am using PyUnit for functionality and UI testing with Selenium and very happy with it, So I have hard time understanding why it will be useless for you. It is just a way to run tests. Create XML files with run results for Jenkins. PyUnit works like a charm for me. Commented Apr 23, 2018 at 15:36

Use this construction when you intialize your page elements to achieve what you need:

public int timeOut = 10;
PageFactory.initElements(new AjaxElementLocatorFactory(driver, TimeoutValue), this);

Here you can find some more examples.

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.