Changing our Page Object to use LoadableComponent

Now that we have learned about LoadableComponents, we should have a look at it in action. We need to make changes to our Java class.

  1. The following is how the code should look so far:
    public class Chapter2 {
      WebDriver selenium;
    
      @FindBy(how= How.NAME, using="verifybutton")
      WebElement verifybutton;
    
      public Chapter2(WebDriver selenium){
        this.selenium = selenium;
        if (!"Chapter 2".equalsIgnoreCase(this.selenium.getTitle())){
          selenium.get("http://book.theautomatedtester.co.uk/chapter2");
        }
      }
    
      public boolean isButtonPresent(String button){
        return selenium.findElements(By.xpath("//input[@id='"+button+"']")).size()>0;
      }
    }
  2. If we have a look at our Chapter2 Java class, we can see that we need to extend LoadableComponent ...

Get Learning Selenium Testing Tools - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.