I am using Selenium WebDriver with Java with ChromeDriver.
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.
I get the cell by its XPath based on some parameters relevant to my project. I tried something like the following
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();
The element prints out fine and has an xpath associated with it. No scrolling occurs and no clicking occurs.
Currently getting this error as well at the element.click() line:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
EDIT:
You can find the source for the page here: http://libcal.library.ucsb.edu/rooms.php?i=12405
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