As per your code snippet, there are a couple of issues that might be leading to the unexpected behavior. You're creating a
DataTable
within the loop, causing it to reset with each iteration. To address this, move the
DataTable
creation outside the loop and set the
DataTable
as the
DataSource
after the loop. Below is the updated version of your code:
List<IWebElement> selectElements = drv.FindElements(By.Id("dersler"));
DataTable dt = new DataTable();
foreach (IWebElement select in selectElements)
{
var selectElement = new SelectElement(select);
DataColumn dtcol = new DataColumn(selectElement.Text);
dt.Columns.Add(dtcol);
foreach (IWebElement option in selectElement.Options)
{
DataRow row = dt.NewRow();
row[selectElement.Text] = option.Text;
dt.Rows.Add(row);
}
}
dataGridView1.DataSource = dt;