Quality Testing

Quality is delighting customers

Hi All,

"How to compare two webtables using Selenium tool?", Can you share your answers please?


Views: 2772

Reply to This

Replies to This Discussion

me also wanna to know :)

You have several aproaches

1. ask develepor to give you a good locator, so you will be able to found what table you are working with

2. use your knowledge of xpath or dom object. i will show you how to do that using xpath


If you are using XPATH for yout locator strategy. you will need to underestand how is your table created. this xpath is for element inside first table row of the first table column.



You need to find element saying - "here starts the table" - in our example it is div[@id='Table_ID']

You need to find what element tells you - "this is first row" - div[1]

and that "this is the firs column" - td[1]


So with this knowledge you can answer question - what is Xpath for 2nd row a and 2nd column element going to look like ?


As you can see only 2 parametrs are changing (might be more, depends on developers technique).

You can use every programming language to navigate and to make all sorts of operations and controls using verify....

Ok. you are going to check data in tables. Following is a pseudo code for you.  Develop the actual test code. If you have any problems let me know.


Step 1: get the number of rows using getXpathCount method.  For this method you have to pass xpath for <tr> tag.

Step 2: Iterate over each row and get the number of columns using getXpathCount as above.

Step 3: populate a map with key value pair. Key as 11,12,13... , 21,22,23 and value using getText.


So now you a map look like {11,row-one::col-one},{12,row-one::col-two},....{1N,row-one::col-N},..{NN,row-N::col-N}.


populate another map for another table using the same steps above.  Think now you know what we are going to do. Now iterate the entry sets in maps and check for equality. We are done.







TTWT Magazine





© 2022   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service