I have a table and when I try to scroll through the columns from right to left (i.e from last column to first column) using Actions.MoveToElement() method, the action performed, but the element is still behind the table width. The element is not completely in the viewport of the table. So when I try to click it says element is intercepted with another element and not able to click on it.
Code: Tried both Javascript and actions method and same thing happens.
import org.openqa.selenium.interactions.Actions;
public void scrollToElement(WebElement element) {
// ((JavascriptExecutor) getDriver()).executeScript("arguments[0].scrollIntoView(true);",element);
actions = new Actions(getDriver());
waitForDOMToBeLoaded();
actions.moveToElement(element).build().perform();
waitForDOMToBeLoaded();
}
If you observe the element HTS code column in original code is not completely in viewport during the execution. But when I check the visibility in viewport using this code after scrolling to the element, I am getting true. And if I try to click then I get the error as below. I am totally lost in the clouds.
public Boolean isVisibleInViewport(WebElement element) {
return (Boolean)((JavascriptExecutor)getDriver()).executeScript(
"var elem = arguments[0], " +
" box = elem.getBoundingClientRect(), " +
" cx = box.left + box.width / 2, " +
" cy = box.top + box.height / 2, " +
" e = document.elementFromPoint(cx, cy); " +
"for (; e; e = e.parentElement) { " +
" if (e === elem) " +
" return true; " +
"} " +
"return false; "
, element);
}
Screenshot during execution
Screenshot during execution
Original screen
full screen
Error message:
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <button class="MuiButtonBase-root-378 MuiButton-root-351 MuiButton-text-353 jss665" tabindex="0" type="button" aria-label="sort-button-HTS Code-sort-by-desc">...</button> is not clickable at point (691, 152). Other element would receive the click: <th class="MuiTableCell-root-703 MuiTableCell-head-704 jss654 jss655 MuiTableCell-sizeSmall-707" scope="col" aria-label="table-checkbox">...</th>
(Session info: chrome=122.0.6261.69)
Build info: version: '4.19.1', revision: 'abe0ee07dc'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'
Driver info: org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$KCI95tvJ$ByteBuddy$PGBjE0aS
Command: [c3c9243fc7a1fdf218a46dc2561d0c93, clickElement {id=f.257F1F7CBD62B574E128FB297BA14BE4.d.ADEA7719F7D12F893130A70880BC813C.e.224}]