Webdriver:如何点击一个表的特定行的按钮(C#) [英] Webdriver: How to click on a button for a specific row of a table (C#)

查看:226
本文介绍了Webdriver:如何点击一个表的特定行的按钮(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图片是动态的。测试用例是单击相应的删除按钮,其名称等于测试组2。

The table shown in the picture is dynamic. The test case is to click on the respective Delete button where the name is equal to "Test Group 2".

请建议C#代码。

推荐答案

您可以使用以下方法。传递您正在寻找的值,如测试组2。以下将循环通过表并停止该值。从那里,传入下面点击垃圾桶。

You can use the below method. Pass the value for what you are looking for like "Test Group 2". The below will loop through the table and stop on the value. From there, pass in the below to click the trash can.

 tds[i + 4].Click();

所以查看列,只计数到右边(+)或左( - )。如果你想点击分配按钮,应该是:

So look at the columns and just count to the right (+) or left (-). If you wanted to click the assign button it should be:

tds[i + 2].Click();

如果您在测试组2左侧有一个按钮,您将进入: p>

If you had a button to the left of "Test Group 2" you would pass in:

tds[i - 1].Click();

方法:

 public void ClickTableLink(string value)
 {
 var table =  driver.FindElement(By.Id("assetGroup-table"));
 foreach (var tr in table.FindElements(By.TagName("tr")))
 {
 var tds = tr.FindElements(By.TagName("td"));
for (var i = 0; i < tds.Count; i++)
{
    if (tds[i].Text.Trim().Contains(value))
    {
        tds[i + 4].Click();
        break;
    }

   }
  }
}

这篇关于Webdriver:如何点击一个表的特定行的按钮(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆