title: Selenium Scroll ScrollTable to target element
body: <p>I am using Selenium WebDriver with Java with ChromeDriver.</p>
  
  <p>I want to click on a cell in the table shown below, but because the table overflows and has a scrollbar, there is no guarantee the cell is actually in the view.</p>
  
  <p><a href="https://i.stack.imgur.com/eTa7j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eTa7j.png" alt="enter image description here"></a></p>
  
  <p>I get the cell by its XPath based on some parameters relevant to my project. I tried something like the following</p>
  
  <pre><code>String cellXPath = "/html/body/div/div/section/div/div/div[2]/div/div/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[" + (c.getRow()+2) + "]/td/*[" + (c.getCol()+1) + "]";
  wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(cellXPath)));
  WebElement element = WebDriverUtility.driver.findElement(By.xpath(cellXPath));
  System.out.println("CELL: " + element.toString());
  jse.executeScript("arguments[0].scrollIntoView(true)", element);
  Thread.sleep(500);
  element.click();
  </code></pre>
  
  <p>The element prints out fine and has an xpath associated with it. No scrolling occurs and no clicking occurs. </p>
  
  <p>Currently getting this error as well at the element.click() line:</p>
  
  <pre><code>org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>You can find the source for the page here: <a href="http://libcal.library.ucsb.edu/rooms.php?i=12405" rel="nofollow noreferrer">http://libcal.library.ucsb.edu/rooms.php?i=12405</a></p>
  
  <p>I have tried the solution in the other question where I wait for the element to be attached, or a explicit Thread.sleep, but the issue is that the element is hidden in the table because when the page loads the table is automatically scrolled to the right a certain amount. Thus, the element can be found, but not clicked on. I need to put the element back into the view by invoking a scroll to the cell and then fire the click event. Hope that clarifies the comments</p>