title: Using alternative to try catch exception for end of page link
body: <p>Requirement: Go to the link which is a job search for last 3 days. 
  1) Print job descriptions
  2) Click on the next link to go to next page until you reach the last page</p>
  
  <p>Problem: I am using try catch for no such element found for next link when I reach the last page. Using this solution it stops the script, by looking at the JUNIT bar you will not know if the test passed or failed.It is a grey bar since as I used exit. How can I make this code better so that I  do not have to use that try catch and see a green bar for a passing test?</p>
  
  <p>Code:</p>
  
  <pre><code>import java.util.List;
  import java.util.concurrent.TimeUnit;
  
  import org.junit.Test;
  import org.openqa.selenium.By;
  import org.openqa.selenium.JavascriptExecutor;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.firefox.FirefoxDriver;
  
  public class QAJob {
  
      @Test
      public void jobSearch(){
          WebDriver driver= new FirefoxDriver();
          driver.get("https://www.indeed.com/jobs?as_and=qa+engineer&amp;as_phr=&amp;as_any=&amp;as_not"
                  + "=&amp;as_ttl=&amp;as_cmp=&amp;jt=all&amp;st=&amp;salary=&amp;radius=10&amp;l=Bellevue%2C+WA&amp;fromage=7&amp;limit"
                  + "=10&amp;sort=date&amp;psf=advsrch");
          driver.manage().window().maximize();
  
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  
          //code to scroll down to find the rest pages link
          JavascriptExecutor jse = (JavascriptExecutor) driver;
          jse.executeScript("window.scrollBy(0,1000)", "");
  
          // Find and print the number of pages for the search
          List&lt;WebElement&gt; search_pages=driver.findElements(By.xpath("//div [contains(@class,'pagination')]//a"));
  
          System.out.println("Number of pages found for this search " + search_pages.size());
  
          while(search_pages.size()!=0){
              List&lt;WebElement&gt; job_desc=driver.findElements(By.xpath("//div [contains(@id,'p')][contains(@class,'row')]"));
  
              for(WebElement e:job_desc){
                  String str_job_desc=e.getText();
                  System.out.println(str_job_desc);
              }
              try
              {
                  // closes the pop up that appears 
                  driver.findElement(By.id("popover-x-button")).click();
              }
              catch (Exception e)
              {
  
  
              }
  
              try
              {
                  //click on next link to go to next page
                  driver.findElement(By.xpath("//span[contains(@class,'np')][contains(text(),'Next')]")).click();
  
                  //scroll down
                  JavascriptExecutor jse1 = (JavascriptExecutor) driver;
                  jse1.executeScript("window.scrollBy(0,1000)", "");
              }
              //when I get the exception(because no next link is available) exit.
              catch (org.openqa.selenium.NoSuchElementException e)
              {
                  System.exit(0);
              }
          }
  
      }
  }
  </code></pre>
  
  <p>Thanks in advance for your time and suggestion. </p>