title: Verify Amazon price in asc order-Java Selenium
body: <p>Scenario: Search a product in Amazon and then sort by price low to high.<br>
  The logic that I thought of is- A) go through each page using while page count... B) save the prices in a list C) verify list[i]&lt; list[i]+1 (current value is less than next value).   </p>
  
  <p>Please if you have any better suggestion, kindly mention.</p>
  
  <p>What are the challenges I am having with my code below:<br>
  1) Incorrect page count- the actual count should be 5, that's what I see on page but program prints 6<br>
  2)Price - the program prints a few prices (I don't know what it is printing). When I try the xpath in the page it moves around so I thought it works.<br>
  3) The program ends with an exception</p>
  
  <pre><code>Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element &lt;a href="/s?k=yellow+puma+shoes&amp;amp;s=price-asc-rank&amp;amp;lo=visual_grid&amp;amp;page=4&amp;amp;qid=1558648339&amp;amp;ref=sr_pg_3"&gt;...&lt;/a&gt; is not clickable at point (962, 579). Other element would receive the click: &lt;div class="a-section aok-relative s-image-tall-aspect"&gt;...&lt;/div&gt;
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>public class AmazonPriceTest {
  
      public static WebDriver driver;
      //public static List&lt;WebElement&gt; priceAsc;
  
      public static void main(String[] args) {
          System.setProperty("webdriver.chrome.driver", "C:\\Users\\Downloads\\chromedriver_win32\\chromedriver.exe");
          driver= new ChromeDriver();
          //WebDriverWait wait = new WebDriverWait(driver,30);
          driver.get("https://www.amazon.com/");
  
          driver.findElement(By.xpath("//input[@id='twotabsearchtextbox']")).sendKeys("yellow puma shoe");
          driver.findElement(By.xpath("//input[@value='Go']")).click();
  
          //Implicit wait till page loads
          driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
  
          //Click on result sort option where we will select price low to high
          Select sortBy=new Select(driver.findElement(By.xpath("//select[@name='s']")));
          sortBy.selectByValue("price-asc-rank");
  
  
          //Scroll down to find pagination
          JavascriptExecutor jse = (JavascriptExecutor) driver;
          jse.executeScript("window.scrollBy(0,5000)", "");
          //Number of Pages
          List&lt;WebElement&gt; pagesFound=driver.findElements(By.xpath("//ul[@class='a-pagination']//li//a[contains(@href, '/s?k=yellow+puma+shoes')]"));
          System.out.println("Pages found " + pagesFound.size());
  
          //Will click on Next link until we reach the last page and keep on saving price in list
          while(pagesFound.size()!=0){
              driver.findElement(By.xpath("//a[contains(text(),'Next')]")).click();
              List&lt;WebElement&gt; priceAsc=driver.findElements(By.xpath("//span[@class='a-offscreen']"));
              System.out.println(priceAsc.size());
          }
  
      }
  
  }
  </code></pre>
  
  <p>If you have few minutes to spare, I could use some help. Thanks in advance for your time. 
  Update**: I made the following change and now it keeps on running never stops  </p>
  
  <pre><code>try{
              while(pagesFound.size() &gt;=0){
                  driver.findElement(By.xpath("//a[contains(text(),'Next')]")).click();
                  List&lt;WebElement&gt; priceAsc=driver.findElements(By.xpath("//span[@class='a-price']//span[@class='a-offscreen']"));
                  //System.out.println(priceAsc.size());
                  for(int i=0;i&lt;priceAsc.size();i++){
                      System.out.println(priceAsc.get(i).getText());
                  }
              }
          }
          catch (org.openqa.selenium.NoSuchElementException e)
          {
              System.exit(0);
          }
      }
  
  }
  </code></pre>