I am using selenim with c#. I want to increase the div number one by one each time. I am trying the following codes by beginning the second line.but it doesn't work What is the solution?
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
var val1 = dataGridView1.Rows[i].Cells[3].Value.ToString().;
driver.FindElement(By.XPath("/html/body/app-root/app-auth/app-public/app-card/div/div/div[6]")).Click();
driver.FindElement(By.XPath("/html/body/app-root/app-auth/app-public/app-card/div/div/div[6]/div[i+2]/div/div[1]/kendo-datepicker/button/span")).Click();
Thread.Sleep(100);
driver.FindElement(By.XPath("/html/body/app-root/app-auth/app-public/app-card/div/div/div[6]/div[i+2]/div/div[1]/kendo-datepicker/button/span")).Click();
}
Muhammad Imran AnsariPosted Oct 28, 2023, 2:37 PM
There are a couple of issues in your code. Firstly, you have an extra dot after the ToString() method call, remove dot from the last. Secondly, the usage of the index i inside the XPath might not work as intended. Here is a revised version of your code with proper string concatenation using string interpolation to dynamically inject the value of i into the XPath expression:
Mehmet FatihPosted Oct 28, 2023, 8:46 PM
Thanks Muhammad Imran Ansari, it works fine. I am gratefull to you. Allah bless you.
Sam HobbsPosted Oct 28, 2023, 4:48 PM
I see you are finding the path:
Multiple times. If it were me, I would find it once and then ensure it was valid then use the result multiple times.
You are using the result of each
XPathquery without checking whether the result is valid. It would be better to ensure a path exists before using it, such as to callClick.