Verifying Data within a Table
I'm currently using Selenium IDE for automating testing on our website.
On my web page, you can add a user (which displays a form for the user to complete), I'm st开发者_JS百科oring certain fields using a storeElementPresent command. Ex. (first name, last name). Once the user completes the form, it displays within a table. Since the table is sorted alphabetically by name, I have no idea where it will be placed.
The problem is that I need some way to locate the new row, examine the cells within it in order to verify its correct with the data that was entered on the form.
Can anyone assist me with this?
There are many ways to approach this.
While you don't know which row contains the target user, you probably know the structure of the table. Since you stored the name, craft an XPath expression matching a row with first_name=John
followed by last_name=Doe
XPath Expression
//table/tbody/tr/td[contains(text(),'${first_name}')]/following-sibling::td[contains(text(),'${last_name}')]
Script
| store | John | first_name |
| store | Doe | last_name |
| verifyElementPresent | //table/tbody/tr/td[contains(text(),'${first_name}')]/following-sibling::td[contains(text(),'${last_name}')] | |
Limitations
Assumes name is unique. If you can't guarantee the stored attributes are unique, you might get a false positive because there could already be a "John Doe" in the table.
精彩评论