简体   繁体   中英

How to scroll horizontally in slick grid using Selenium?

So I have a website that uses slick grid. basically when the browser window is maximized you still have horizontal scrollbar(this is by user design). Now in web automation test(using selenium) I do get total number of columns correct, but without scrolling to the right selenium only gives me column headers that are visible and the other columns that are not in visibility are returning blank or empty string. My question to you guys is have you had similar problem and how you got around this problem. This is my code so far. But it returns blank when slick grid has not loaded new contents without scrolling. I need to be able to somehow scroll to the right to get all the column headers.

int GetColumnIndexByName(string columnName)
{
    VerifyComponentLoaded();
    var colHeaders = Driver.FindElements(By.XPath("somepath"));
    for (int i = 0; i < colHeaders.Count; i++)
    {
        if (colHeaders.ElementAt(i).Text == columnName)
            return i;                    
    }
    Assert.Fail("The columnName {0} was not found.", columnName);
}

You can use the following SlickGrid methods:

grid.setActiveCell(0,0);  // right before the for loop

Then inside your for loop, right at the top:

grid.navigateRight();

That should bring each column into view as needed. But you should be aware that SlickGrid only renders visible columns and rows (plus some buffer) so it's not wise to trust DOM selectors for testing. Especially since SlickGrid will also reuse existing elements and simply replace the inner text when scrolling/paginating vertically and horizontally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM