title: How can I change try catch exception to WebDriverWait
body: <p>I am trying to login and search records based on date selected from a calendar. I have used try catch exception after each step. I need to replace try catch with WebDriverWait. But the problem is that I have fields on the page which are getting identified by id or XPath. So I am not getting a way out how to implement WebDriverWait instead of try catch. Can anyone help me out? Below is my code structure with details.</p>
  
  <pre><code>public class Login {
      public static WebDriver driver;
      String username = "username";
      String password = "password";
      String baseurl = "http://mybusiness.com/login.aspx";
  
  
  public class Details {  
      @Test(priority = 0)
      public void loginpage() {
          //WebDriver driver = new FirefoxDriver();
          System.setProperty("webdriver.chrome.driver","D:\\From H\\Selenium Package\\ChromeDriver\\chromedriver_win32\\chromedriver.exe");
  
          DesiredCapabilities capabilities = DesiredCapabilities.chrome();
          capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
          ChromeOptions options = new ChromeOptions();
          options.addArguments("--test-type");
          options.addArguments("--disable-extensions");
          capabilities.setCapability("chrome.binary","D:\\From H\\Selenium Package\\ChromeDriver\\chromedriver_win32\\chromedriver.exe");
          capabilities.setCapability(ChromeOptions.CAPABILITY, options);
  
  
          driver = new ChromeDriver(capabilities);
          driver.manage().deleteAllCookies();
          driver.manage().window().maximize();
          driver.get(baseurl);
  
          try {
              Thread.sleep(10000); // 1000 milliseconds is one second.
          } catch (InterruptedException ex) {
              Thread.currentThread().interrupt();
          }
          WebElement username = driver.findElement(By.id("UserName"));
          username.sendKeys(username);
          try {
              Thread.sleep(10000); // 1000 milliseconds is one second.
          } catch (InterruptedException ex) {
              Thread.currentThread().interrupt();
          }
          WebElement password = driver.findElement(By.id("Password"));
          password.sendKeys(password);
          try {
              Thread.sleep(10000);
          } catch (InterruptedException ex) {
              Thread.currentThread().interrupt();
          }
          WebElement button = driver.findElement(By.id("ButtonClick"));
          button.click();
          try {
              Thread.sleep(10000);
          } catch (InterruptedException ex) {
              Thread.currentThread().interrupt();
          }
      }
  
      // Selecting a date from date picker
      @Test(priority = 1)
      public void RecordSearch() {
          WebElement calendar = driver.findElement(By.id("CalendarId"));
          calendar.click();
          try {
              Thread.sleep(5000); // 1000 milliseconds is one second.
          } catch (InterruptedException ex) {
              Thread.currentThread().interrupt();
          }
  
          WebElement month = driver.findElement(By.xpath("XPath"));
          month.click();
          try {
              Thread.sleep(5000); // 1000 milliseconds is one second.
          } catch (InterruptedException ex) {
              Thread.currentThread().interrupt();
          }
  
          WebElement day = driver.findElement(By.xpath("XPath"));
          day.click();
          try {
              Thread.sleep(5000); // 1000 milliseconds is one second.
          } catch (InterruptedException ex) {
              Thread.currentThread().interrupt();
          }
  
          WebElement submit = driver.findElement(By.id("Submit"));
          submit.click();
          try {
              Thread.sleep(10000); // 1000 milliseconds is one second.
          } catch (InterruptedException ex) {
              Thread.currentThread().interrupt();
          }
  
      }
  
          driver.close();
  }
  </code></pre>