title: How to make click on the Update Button in the shopping Cart Page - Url="http://live.guru99.com/"
body: <p><a href="https://i.stack.imgur.com/8BcWL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8BcWL.png" alt="enter image description here"></a>Even though x-path  picking  the element , and i tried with java executor, but at the time of code run , it is only able to click on update button for  the first element in the cart . Below is the Code : </p>
  
  <p>Here once after placing 3 products in the cart i have added there text boxes into a list :</p>
  
  <p>I have attached the image :
       Url="http://live.guru99.com/"</p>
  
  <pre><code>List&lt;WebElement&gt; li2 =driver.findElements(By.xpath(".//td[@class='product- 
  cart-actions']/input"));
  
  
  for(int j=0;j&lt;li2.size();j++)
      {
  
          if(j==0)
          {
              li2.get(j).clear();
          li2.get(j).sendKeys("4");
          driver.findElement(By.xpath(".//td[@class='product-cart-actions']/button[@title='Update']")).click();
          li2 =driver.findElements(By.xpath(".//td[@class='product-cart-actions']/input"));
          }
          else if(j==1)
          {
              li2.get(j).clear();
              li2.get(j).sendKeys("2");
              //wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//td[@class='product-cart-actions']/button[@title='Update' and @type='submit']")));
              //driver.findElement(By.xpath(".//td[@class='product-cart-actions']/button[@title='Update' and @type='submit']")).isDisplayed();
  
              WebElement element = driver.findElement(By.xpath(".//td[@class='product-cart-actions']/button[@title='Update' and @type='submit']"));
              try {
                  if (element.isEnabled() &amp;&amp; element.isDisplayed()) {
                      System.out.println("Clicking on element with using java script click");
  
                      ((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
                  } else {
                      System.out.println("Unable to click on element");
                  }
              } catch (StaleElementReferenceException e) {
                  System.out.println("Element is not attached to the page document "+ e.getStackTrace());
              } catch (NoSuchElementException e) {
                  System.out.println("Element was not found in DOM "+ e.getStackTrace());
              } catch (Exception e) {
                  System.out.println("Unable to click on element "+ e.getStackTrace());
              }
          //  if (element.isDisplayed()) {
              //  element.click();
              //}
  
  
              li2 =driver.findElements(By.xpath(".//td[@class='product-cart-actions']/input"));
          }
  
  
          else
          {
              li2.get(j).clear();
              li2.get(j).sendKeys("3");
  
              WebElement element1 = driver.findElement(By.xpath(".//td[@class='product-cart-actions']/button[@title='Update']"));
  
          if (element1.isDisplayed()) {
               element1.click();
              }       
          }
  </code></pre>