title: Using the builder pattern and Selenium to execute different searches with different combinations of criteria
body: <p>I am using Selenium to automate some test cases around searching with multiple combinations of criteria. In my PageObject for my search page, I've created my Builder class as such</p>
  
  <pre><code>public class AdvancedSearchPage extends PageObject {
  
  public static class Query {
          private WebDriver driver;
  
          private String commonName;
          private String contactEmail;
          private int certificateType;
          private int status;
  
  
          public Query(WebDriver driver) {
              this.driver = driver;
          }
  
          public Query setCommonName(String value) {
              this.commonName = value;
              return this;
          }
  
          public Query setContactEmail(String value) {
              this.contactEmail = value;
              return this;
          }
  
          public Query setCertificateType(int value) {
              this.certificateType = value;
              return this;
          }
  
          public Query setStatus(int value) {
              this.status = value;
              return this;
          }
  
           public AdvancedSearchPage build() {
              return new AdvancedSearchPage(driver,this);
          }
      }
  
      private AdvancedSearchPage(WebDriver driver, Query q) {
          super(driver);
          // Navigates to AdvancedSearchPage url and authenticates if necessary
          this.init(URL);
  
          this.setCommonName(q.commonName);
          this.setContactEmail(q.contactEmail);
          this.setCertificateType(q.certificateType);
          this.setStatus(q.status);
  
      }
  }
  </code></pre>
  
  <p>In my private constructor, I take the values and use the <code>AdvancedSearchPage</code> object's 'setters' which simply sets the value for the relevant <code>WebElement</code>. </p>
  
  <p>When I build a Query with just common name, the other fields are set. How can I modify the private constructor to only set the values of <code>WebElement</code>s that have been defined when building the Query?</p>