Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jimevans/190e6494ced4674a37122a3910707888 to your computer and use it in GitHub Desktop.
Save jimevans/190e6494ced4674a37122a3910707888 to your computer and use it in GitHub Desktop.
Selenium
DataTable dt = new DataTable();
//Adding Number of Col of Data Output
string Header = driver.FindElement(By.CssSelector("#gridComponent > div.k-grid-header > div > table > thead > tr")).Text;
// Get rows strings
foreach (string row in Header.Split('\r'))
{
DataRow dataRow = dt.NewRow();
}
string[] HeaderSplit = Header.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
// create DataTable
foreach (string c in HeaderSplit)
{
dt.Columns.Add(c);
}
// add extra cols
if (dt.Columns.Count < 30)
{
for (int i = dt.Columns.Count - 1; i <= 30 - 1; i++)
{
dt.Columns.Add(i.ToString());
}
}
var table = driver.FindElement(By.CssSelector("#gridComponent"));
//Get Row value
foreach (var row in table.FindElements(By.TagName("tr")))
{
//Configure Number of Col and row
int cellIndex = 0;
// Use a list instead of an array
List<string> arr = new List<string>();
//Get Cell Data
foreach (var cell in row.FindElements(By.TagName("td")))
{
// Skip the first column in the row by checking
// if the cell index is 0.
if (cellIndex != 0)
{
string cellValue = "";
Console.WriteLine(cell);
var checkboxes = cell.FindElements(By.CssSelector("input[type='checkbox']"));
if (checkboxes.Count > 0)
{
bool isChecked = false;
isChecked = checkboxes[0].Selected;
cellValue = isChecked.ToString();
}
else
{
cellValue = cell.Text;
}
arr.Add(cellValue);
}
cellIndex++;
}
dt.Rows.Add(arr.ToArray());
}
dataGridView1.DataSource = dt;
driver.FindElement(By.CssSelector("#gridComponent > div.k-pager-wrap.k-grid-pager.k-widget.k-floatwrap > ul > li:nth-child(3)")).Click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment