Question

I'm working on ui automation and recently discovered one interesting behavior. Sometimes I need to scroll to some particular element and I've been using both, JS function to scroll to element and actions.moveToElement(WebElement)

This seem to work for any checkboxes, textboxes, buttons types of elements, but when i need to move to the table cell () of the table which has multiple columns - see that table is being shift to the left, this happens almost every time. Let say there is a table 5x5 and i'm only looping over 5th column, when i do scroll2element via either of those 2 functions - the whole table is getting messed up. all the previous columns would disappear and my 5th column is shifting all the way to the left.

I found the workaround - instead of scrolling to specific table cell i scroll to the button that is located on top of that table, but just out of curiosity, if anyone experienced such an issue and what did they do? Thanks

Was it helpful?

Solution

I think you problem could be with selectors.

Try using CSS selectors over the XPath, from my life experience XPath doesnt work as well ass CSS.

Also i'm always using JS and never had any problems.

try that

   WebElement x = driver.findElement(by);
        ((JavascriptExecutor) driver).executeScript(
                "arguments[0].scrollIntoView();", x);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top