Selenium c#:无法找到生成了 id 的 Xpath
Selenium c#: not able to find Xpath with id generated
我正在使用 table,当在 table 上找到一个名字时:我想单击相应的删除按钮。
IList<IWebElement> CtrlRow = option.FindElements(By.TagName("td"));
for (int CountRows = 0; CountRows < CtrlRow.Count; CountRows++)
{
IWebElement row = CtrlRow[CountRows];
Console.WriteLine("Found content: " + row.Text.ToString());
if (row.Text.ToString().Equals(t))
{
int myElementRowNumber = CtrlRow.IndexOf(row);
var ty = @"(//td)["+ myElementRowNumber + "]";
var DeleteRow = @"//tbody/" + "tr[" + myElementRowNumber + "]" + "/td[6]/a[1] ";
var tt = row.FindElement(By.XPath(ty));
Console.WriteLine("Found Controller ID in System List: " + t);
try
{
row.FindElement(By.XPath(DeleteRow)).Click();
此处,行索引未正确显示为相应的删除按钮。
我做了什么:
1:tried 将删除的索引作为行索引进行操作:完成工作
2:尝试获取具有我的元素名称的行的 xpath,以便复制正确的索引(在 Xpath 中,索引是正确的),并操作 Delete xpath: cant get Xpath in ID of the row.
我正在使用 C# 使用 Selenium。
问题出在这一行:
var ty = @"(//td)["+ myElementRowNumber + "]";
您没有使用任何 ID 属性,更改为这个:
var ty = "(//td)["+ "@ID='" + myElementRowNumber + "']";
我正在使用 table,当在 table 上找到一个名字时:我想单击相应的删除按钮。
IList<IWebElement> CtrlRow = option.FindElements(By.TagName("td"));
for (int CountRows = 0; CountRows < CtrlRow.Count; CountRows++)
{
IWebElement row = CtrlRow[CountRows];
Console.WriteLine("Found content: " + row.Text.ToString());
if (row.Text.ToString().Equals(t))
{
int myElementRowNumber = CtrlRow.IndexOf(row);
var ty = @"(//td)["+ myElementRowNumber + "]";
var DeleteRow = @"//tbody/" + "tr[" + myElementRowNumber + "]" + "/td[6]/a[1] ";
var tt = row.FindElement(By.XPath(ty));
Console.WriteLine("Found Controller ID in System List: " + t);
try
{
row.FindElement(By.XPath(DeleteRow)).Click();
此处,行索引未正确显示为相应的删除按钮。 我做了什么: 1:tried 将删除的索引作为行索引进行操作:完成工作 2:尝试获取具有我的元素名称的行的 xpath,以便复制正确的索引(在 Xpath 中,索引是正确的),并操作 Delete xpath: cant get Xpath in ID of the row.
我正在使用 C# 使用 Selenium。
问题出在这一行:
var ty = @"(//td)["+ myElementRowNumber + "]";
您没有使用任何 ID 属性,更改为这个:
var ty = "(//td)["+ "@ID='" + myElementRowNumber + "']";