0

I am trying to figure out how to use explicit wait in Selenium using the POM structure. I tried to google, but could not find any leads.

4
  • 1
    What does POM have to with explicit wait?
    – Mate Mrše
    Commented Nov 17, 2021 at 7:35
  • What programming language do you use?
    – Alexey R.
    Commented Nov 17, 2021 at 10:42
  • @AlexeyR. I am using JAVA
    – user
    Commented Nov 17, 2021 at 11:50
  • 1
    Then you a probably talking about PageFactory implementation of POM. If so, you can take a look at this example.
    – Alexey R.
    Commented Nov 17, 2021 at 12:50

2 Answers 2

1

The Page Object pattern is about creating an API for your pages, to create functions named after actions you can take in the page.

Naturally, to perform certain actions, you need to wait certain elements to be ready to be acted upon. Thus, you can simply add the waits inside the functions specifically:

class PaymentPage {
  
  fun fillUpForm(creditCardNumber) {
      
     creditCardNumberField.fill(creditCardNumber);
     WebDriverWait wait = new WebDriverWait(driver, 30);
   
     wait.until(ExpectedConditions.visibilityOfElement(greenCheckmarkForValidCreditCardNumber);
     performPaymentButton.click();
   }

  }

}

The function fillUpForm will hide all necessary knowledge to perform the action of filling up the form, its clients (tests) need to know only that it needs to pass the credit card number. If some other condition come to be necessary before clicking the perform payment button, you need to change only the fillUpForm.

-1

According to security testing services, one of the ways to implement POM in a framework using Selenium and Java,is to create a Resusable Resources class which will include all the explicit waits, click, type functionalities and we can import that class in all the required page classes and use the same.

To implement explicit wait,write a function as follows in your reusable resources class and call it in the pages as and when required.

public static WebDriverWait wait;

public static void setExplicitWait(int seconds){
   wait = new WebDriverWait(driver, seconds);
}

Now in the pages, to call this function, we call follow this approach:-

ReusableResources.setExplicitWait(10).until(ExpectedConditions.elementToBeClickable(abcButton));

This functionality will wait for 10 seconds before throwing any error.

This sums up the concept of using Explicit waits in POM.

1
  • Your link doesn't talk anything about the topic nor is a reference for the information that you gave. Commented Nov 18, 2021 at 13:24

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.