0

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);
}
Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
DoodleKana
  • 2,106
  • 4
  • 27
  • 45

1 Answers1

0

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.

idbehold
  • 16,833
  • 5
  • 47
  • 74
  • can you explain to me what you mean by slickgrid methods? Is there library for slick grid to work with in c#? – DoodleKana Sep 29 '14 at 17:40
  • @DoodleKana not that I know of, the above is javascript you'd have to execute on the page. See here for an example of how to do that: http://stackoverflow.com/a/6285793/1397319 – idbehold Sep 29 '14 at 17:49
  • Thank you for the reply. Yes I am aware of that js executor in c#. When I execute above jscript I get "unknown error: grid is not defined." – DoodleKana Sep 29 '14 at 20:26
  • Also I did not realize I asked this question a year ago, and asked similar question today again only to stumble across my same question I asked a year ago. Here is my new question on stackoverflow. http://stackoverflow.com/questions/26104952/selenium-chrome-webdriver-how-to-scroll-horizontally – DoodleKana Sep 29 '14 at 20:27
  • upon closer inspection, i see slick.column-select-plugin.js, slick.comment-plugin.js, slick.pjax-link-plugin.js, slick.rowselectionmodel.js, but I do not see slick.grid.js which I believe is where the function you mentioned is declared. I have no idea how my slickgrid website without slick.grid.js working. But i guess it sounds more like a helper kind of file. – DoodleKana Sep 29 '14 at 21:30