2

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?

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried the same using it in a loop as selenium.GetTable("UserManagement.i.1") where I want to iterate through loop but it wont work..instead selenium.GetTable("UserManagement.0.1") it works..ANy idea why
@sam what values of i are you iterating over?
following is what I am trying to do i is a counter to numof rows. For i As Integer = 1 To NumOfRows Dim strTableColumn As String = selenium.GetTable("Group.i.1") If (strTableColumn = pword) Then ReturnValue = i IsFound = True Exit For End If Next
@sam looks like you have 2 issues: you're starting at 1 instead of 0 and you need to use string concatenation to build the locator "Group." + i + ".1" instead of "Group.i.1"
1

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

1 Comment

I tried with the same solution you provide. But xpath is not taking i(counter) instead if you use a static row no it works. Any other possible solution
1

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.