如何使用selenium遍历表?

发布于 2024-09-05 12:43:55 字数 222 浏览 4 评论 0原文

我有一个名为 UserManagement 的表,其中包含有关用户的信息。每当创建新用户时,该表都会更新。如果我创建两个用户,那么我需要检查是否实际创建了两个用户。表包含 ID、用户名、名字、姓氏、日期..ctc。这里ID会自动生成。
我正在运行 Selenium-TestNG 脚本。使用 Selenium,我如何获取我创建的两个用户的用户名?我应该遍历表吗?如果是这样,如何迭代表?

I have a table called UserManagement that contains information about the user.This table gets updated whenever new user is created. If i create two users then i need check whether two users are actually created or not. Table contains ID,UserName,FirstName,LastName,Bdate..ctc. Here ID will be generated automatically.
I am running Selenium-TestNG script.Using Selenium,how can i get the UserName of the two users which i have created? Should i have to iterate through table? If so how to iterate through the table?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

月竹挽风 2024-09-12 12:43:55

使用 ISelenium.GetTable(string) 获取所需表格单元格的内容。例如,
selenium.GetTable("UserManagement.0.1");
将返回表的第一行和第二列的内容。然后您可以断言正确的用户名或用户名出现在表中。

Use ISelenium.GetTable(string) to get the contents of the table cells you want. For example,
selenium.GetTable("UserManagement.0.1");
will return the contents of the table's first row and second column. You could then assert that the correct username or usernames appear in the table.

无悔心 2024-09-12 12:43:55

在变量 rowcount 中使用 Selenium.getxpathcount(\@id = fjsfj\td\tr") 获取行数

在变量中给出列计数

例如:

int colcount = 5;

给出 req ie 新用户

String user1 = "ABC"

for(i = 0;i <=rowcount;i++)
{
   for(j=0;j<=colcount;j++)
   {
      if (user1==selenium.gettable("//@[id=dldl/tbody" +i "td"+j))
      {
         system.out.println(user1  + "Inserted");
         break;
      }
      break;
   }
}

Get the count of rows using Selenium.getxpathcount(\@id = fjsfj\td\tr") in a variable rowcount

Give the columncount in a variable

Ex:

int colcount = 5;

Give the req i.e New user

String user1 = "ABC"

for(i = 0;i <=rowcount;i++)
{
   for(j=0;j<=colcount;j++)
   {
      if (user1==selenium.gettable("//@[id=dldl/tbody" +i "td"+j))
      {
         system.out.println(user1  + "Inserted");
         break;
      }
      break;
   }
}
2024-09-12 12:43:55

使用以下方法获取行数:

int noOfRowsInTable = selenium.getXpathCount("//table[@id='TableId']//tr");

如果您要获取的 UserName 位于固定位置,假设在第二个位置,然后对每一行进行迭代,如下所示:

selenium.getText("xpath=//table[@id='TableId']//tr//td[1]");< /code>

注意:我们可以使用相同的过程找到该表中的列数

int noOfColumnsInTable = selenium.getXpathCount("//table[@id='TableId']//tr //td");

Get the number of rows using:

int noOfRowsInTable = selenium.getXpathCount("//table[@id='TableId']//tr");

If the UserName you want to get is at fixed position, let's say at 2nd position, then for each row iterate as given below:

selenium.getText("xpath=//table[@id='TableId']//tr//td[1]");

Note: we can find the number of columns in that table using same procedure

int noOfColumnsInTable = selenium.getXpathCount("//table[@id='TableId']//tr//td");

深府石板幽径 2024-09-12 12:43:55

一般来说,是这样的吗?

table = @browser.table(:id,'tableID')
table.rows.each do |row|
    # perform row operations here
    row.cells.each do |cell|
        # do cell operations here
   end
end

Generically, something like this?

table = @browser.table(:id,'tableID')
table.rows.each do |row|
    # perform row operations here
    row.cells.each do |cell|
        # do cell operations here
   end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文