First of all, I apologize because I had never worked on a grid before. I thought it would be a frame, and it would be easier to switch and then scroll the item to a JavascriptExecutor . But alas! This does not apply to the grid.
And there should be a table when the grid is involved.
Now this is what worked for me.
First click on any visible element on the grid to get it in focus. Then scroll through the grid using the grid locator (xpath, id, etc.) using "Keys.PAGE_DOWN" until you find the item you need. If the element is not found on each scroll, than it handles the exception, which it raises and scrolls again.
Note. Remember to give some sleep time after each scroll.
I automated one grid with a sample and attached an example of working code below. Hope this helps in solving the problem:
import java.io.IOException; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class ScrollGrid{ public static void main(String[] args) throws IOException, InterruptedException{ WebDriver driver = new FirefoxDriver(); driver.get("https://demos.devexpress.com/ASPxGridViewDemos/PagingAndScrolling/VirtualPaging.aspx"); driver.manage().window().maximize();
Note: Now this works correctly. It will exit the loop if an element is found or if it is not found after 250 scrolls. '250' is a relative number. You can change it to the number of scrolls you want to perform in the grid.
source share