I want to search for student numbers in the datagridview on the web page with Selenium and click on the image link at the beginning of the number line found. But I couldn't understand the logic. Would you mind helping me, plaese?


I want to search for student numbers in the datagridview on the web page with Selenium and click on the image link at the beginning of the number line found. But I couldn't understand the logic. Would you mind helping me, plaese?


Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mehmet FatihPosted Jan 11, 2024, 7:41 AM
I am sorry to say that the result is the same.
Naimish MakwanaPosted Jan 11, 2024, 7:22 AM
You need to change you variable name. in find element
Mehmet FatihPosted Jan 11, 2024, 7:06 AM
I am getting an error like that.
Naimish MakwanaPosted Jan 11, 2024, 7:00 AM
The error you’re encountering is due to the redeclaration of
dataGridView1as a local variable, which is hiding the fieldForm1.dataGridView1.To resolve this issue, you can avoid redeclaring
dataGridView1inside the method where this code is written. Instead, you can use a different variable name for theIWebElementthat you’re trying to find withWebDriverWait.Here’s how you can modify your code:
In this modified code, I’ve changed the name of the
IWebElementfromdataGridView1togridElementto avoid the conflict with the existingdataGridView1field12. Please replace"my link"with your actual URL and adjust the XPath queries as needed.Thanks
Mehmet FatihPosted Jan 11, 2024, 6:53 AM
Thanks Naimish for your help. I modified my codes with yours. But I am getting an errror in this line.
IWebElement dataGridView1 = wait.Until(driver => driver.FindElement(By.Id(val0)));
I am defining the student number like that (Hata CS0844 Ifade edilmeden önce 'dataGridView1' yerel degiskeni kullanilamiyor. Yerel degiskenin bildirimi 'Form1.dataGridView1' alanini gizler.. In English: Before being expressed, 'DatagridView1' local variable cannot be used. The notification of the local variable hides the field of 'form1.DatagridView1' field. )
var val0 = dataGridView1.Rows[i].Cells[0].Value?.ToString();//student number in the datagrdiview
driver.Navigate().GoToUrl("my link")
WebDriverWait wait = new WebDriverWait(drv, TimeSpan.FromSeconds(10));
IWebElement dataGridView1 = wait.Until(driver => driver.FindElement(By.Id(val0))); // this line is giving error.
IWebElement studentNumberElement = drv.FindElement(By.XPath("//td[contains(text(), 'val0')]")); With this line, the primary line that is defined as the number is overlapping ..
IWebElement imageLink = studentNumberElement.FindElement(By.XPath("/html/body/form[2]/div[4]/div[1]/div[4]/div/div/div[2]/div/div["+(i+1)+"]/div/div[2]/h6"));
imageLink.Click();
Naimish MakwanaPosted Jan 11, 2024, 4:29 AM
Here’s a basic example of how you might use Selenium WebDriver in C# to search for student numbers in a datagridview and click on the image link at the beginning of the number line found.
Please note that this is a simplified example and the actual code might need to be adjusted based on the structure of your webpage.
In this code:
"http://your-web-page-url.com"with the URL of your webpage."datagridview-id"with the id of your datagridview element.'student-number'with the actual student number you’re searching for.Remember to install the Selenium WebDriver and ChromeDriver NuGet packages in your project. You can do this in Visual Studio by right-clicking on your project -> Manage NuGet Packages -> Search for Selenium.WebDriver and Selenium.Chrome.WebDriver -> Install. Also, ensure that the ChromeDriver version matches the version of Chrome installed on your machine. If they don’t match, you might encounter issues.
I hope this helps! Let me know if you have any other questions. ??