首页 > 解决方案 > 如何在网格中的多个记录中选择第一条记录复选框?

问题描述

我在下面尝试过

IWebElement selectchk = driver.FindElement(By.XPath("//input[@type='checkbox' and starts-with(@id,'ctl00_UserContentArea_rgBulkSFA_ctl00_')]"));

但问题是网格中的所有复选框都以 Id 开头,因此所有复选框都被选中。请帮忙!

标签: c#selenium-webdriver

解决方案


试试这个 xpath,它只会给出列表的第一个元素:
driver.FindElement(By.XPath("(//input[@type='checkbox' and starts-with(@id,'ctl00_UserContentArea_rgBulkSFA_ctl00_')])[1]"));


推荐阅读