I am pulling the dropdown elements into the datagridview with Selenium, but all the drawn elements are displayed in a single cell. How can I pull all the elements one by one in the rows of the same column?

IList
foreach (IWebElement option in options)
{
for (int i = 0; i < options.Count; i++)
{
dataGridView1.Rows[0].Cells[1].Value = option.Text.ToString();
}
}
Mehmet FatihPosted Jan 17, 2024, 8:48 PM
Naimish, the error code English is like that "Rows cannot be programmatically added to the datagridview's rows collection when the control is data bound."
Mehmet FatihPosted Jan 17, 2024, 2:52 PM
I have changed my codes as in the following. But I still have a problem. I want to list a lesson in each line. All courses are listed in a single line. How can I correct this situation.?The second problem is how can I print these in the 3rd column?
IList selectElements = drv.FindElements(By.Id("dersler")); lst = new List();
foreach (IWebElement select in selectElements)
{
var selectElement = new SelectElement(select);
List
lst.Add(select.Text);
DataTable dt = new DataTable();
DataColumn dtcol = new DataColumn(select.Text);
dt.Columns.Add(dtcol);
for (int i = 0; i < lst.Count; i++)
{
dataGridView1.DataSource = dt;
}
}
Naimish MakwanaPosted Jan 17, 2024, 11:15 AM
Can you paste you error in english ?
Mehmet FatihPosted Jan 17, 2024, 11:12 AM
Both Package Selenium.WebDriver and Package Selenium.Support are intalled. I hve tried the second alternative but nothing seems. I modifed the first alternative like that
IList options = drv.FindElements(By.Id("dersler")); // tüm dropdown listesini veriri
for (int i = 0; i < options.Count; i++)
{
IWebElement element = drv.FindElement(By.Id("ddlDersler")); // replace "id" with the id of your element
//string text = element.Text;
int rowIndex = dataGridView1.Rows.Add(); // Add a new row
dataGridView1.Rows[rowIndex].Cells[1].Value = element.Text.ToString();
}
}
But in this case I am getting the following error.
Naimish MakwanaPosted Jan 17, 2024, 10:29 AM
It seems like you’re using Selenium with C#, and you’re trying to use
SelectandgetText(). In C#, the equivalent methods are a bit different:SelectElementclass from theOpenQA.Selenium.Support.UInamespace1. Here’s an example:getText()isTextproperty1. Here’s an example:If you’re still facing issues, you might need to check if you have the necessary Selenium WebDriver bindings for .NET installed. You can do this by going to the NuGet package manager in Visual Studio and checking if
Selenium.WebDriverandSelenium.Supportpackages are installed2.If they’re not installed, you can install them by running the following commands in the Package Manager Console:
Please replace
"id"and"Option"with the actual id of your dropdown and the actual option you want to select respectively. If you have any specific requirements.Thanks
Mehmet FatihPosted Jan 17, 2024, 10:16 AM
I am getting errors in these circled places. Do I need to upload anything to nuGet?
Naimish MakwanaPosted Jan 17, 2024, 9:47 AM
To pull all the dropdown elements into separate rows of a DataGridView, you can follow these steps:
This will create a new row for each dropdown element and set the value of a cell in that row to the text of the dropdown element12.
Please replace
"id"and"YourColumnName"with the actual id of your dropdown and the actual name of your column respectively. Also, please make sure that the DataGridView allows adding new rows. You can setdataGridView1.AllowUserToAddRows = true;to allow this.Remember, this is a basic example. Depending on your exact requirements and the structure of your DataGridView, you might need to adjust this code. For example, if you have multiple columns and you want to add values to them, you would need to set the values for those cells too. If you have any specific requirements.
Thanks