0

I'm trying to read an Agnostic Grid on a web page using selenium c# and want to store the Text based on the column name. I'm not that great fan of DataTable so I preferred List over DT.

Problem: The grid has scrollbar usng which it can be scrolled right or left. Since there are only few rows there is no vertical scrollbar. After inspecting the element, I get to know that only few div's are generated for the ag. When I scroll towards right using the scrollbar, the div's are generated for the right side columns. And once I scroll back to left, the later generated div's are gone. So, in short, div's are generated only for visible columns.

what I have tried so far: I read the grid using

IList<IWebElement> agGrid = driver.FindElements(GetLocator("//div[@class='ag-center-cols-container']//div[@role='row']"));

than I iterate through each row to get the column values and tried many ways to read the column values:

foreach (IWebElement row in agGrid)
{
    if (row.Text.ToString() == "")
        continue;
    else
    {
        //get first row and click on it to hightlight
        IList<IWebElement> RowData = row.FindElements(By.TagName("div"));
        RowData[0].Click();
        
        //tried to scroll towards end
//IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
//js.ExecuteScript("javascript:window.scrollBy(250,350)");

RowData = row.FindElements(By.TagName("div"));

//get data using colindex attribute. But I was not aware exactly how to do this
//IList<IWebElement> RowData1 = row.FindElements(By.("aria-colindex"));
List<string> dat = RowData.Select(x => x.Text).ToList(); //this doesn't give all the data

//WebElement.SendKeys(Keys.ArrowRight);

//find the horizontal scrollbar element & than scroll
//IWebElement element = driver.FindElement(By.Id("ag-body-horizontal-scroll-container"));
//element.SendKeys(Keys.ArrowRight);
//Actions actions = new Actions(driver);
//actions.MoveToElement(element);
//actions.Perform();

//find the last column and than scroll
IWebElement element = row.FindElement(By.CssSelector("div[@aria-colindex='30']"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
Thread.Sleep(500);

    }
}

None of the above methods worked. So had to post a question. Can anyone please help me with this. Thanks in advance.

1
  • Without knowing the url , it will be hard to help you with a answer Commented Jun 25 at 17:14

0

Browse other questions tagged or ask your own question.