Looking for a way to scroll within an inner window (i.e. div)? Check out this helpful website: How to scroll to an element inside a div?
I came across some Javascript solutions, but I'm struggling with passing values back to Java while using the executor. My code involves a div window with hidden elements at the bottom that only appear when scrolled to. To tackle this, I attempted scrolling a large number in hopes of covering all possible scenarios.
My current approach involves scrolling to the top and then proceeding like this:
String sid = rolesScroller.getAttribute("id");
js.executeScript("document.getElementById('" + sid + "').scrollTop -= 1000");
js.executeScript("document.getElementById('" + sid + "').scrollTop += 1000");
waitForXPathVisibility("Scroll", ROLES_SCROLLER_X);
Is this method acceptable, or should I determine the exact amount to scroll and do so precisely?
I noticed there's element.scrollHeight property. Do scrollTop values range from 0 to scrollHeight? Are both units measured in pixels?
The div elements contain nested nodes which can expand to reveal more contents. Every time I search for a value, I have to ensure everything is visible by scrolling as mentioned above. While my current approach works to some extent, I encounter StaleElementException occasionally after scrolling. Performing a waitForStaleElement() sometimes results in errors stating that the element didn't go stale. Is there a way to confirm that all actions are completed after executing JavaScript to avoid such issues?
To Summarize
Can JavaScript variables be passed back to Java when using the executor from Java/Selenium, especially for subsequent JavaScript commands?
How can the completion of a JavaScript command be assured before proceeding, preventing potential Stale Element exceptions when accessing elements in the scrolled div?