开发者

How to iterate through table using 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 genera开发者_JAVA百科ted 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?


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.


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;
   }
}


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");


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜