Skip to content
CodeKruPro

Read specific cells from a table

Automation taskEasy-MediumAsked in: Accenture, Infosys, TCS, Wipro

"Get the salary of the fourth employee." Read the cells by row and column, or by id when the cells have one. In a real interview, add how you would find the row by an employee name instead of by position.

Get a Table Cell Value by Its id

Get Specific Table Cell Value

You can navigate to a specific cell using row and column indices or by element IDs.

The employee table has cells with IDs like emp1Name, emp3Dept, etc.

Table Cell ID Pattern:

<table id="employeeTable">
  <tbody>
    <tr>
      <td id="emp1Name">John Smith</td>
      <td id="emp1Age">30</td>
      <td id="emp1Dept">Engineering</td>
      <td id="emp1Salary">$80,000</td>
    </tr>
    <tr>
      <td id="emp2Name">Jane Doe</td>
      <td id="emp2Age">25</td>
      <td id="emp2Dept">Marketing</td>
      <td id="emp2Salary">$65,000</td>
    </tr>
    <!-- Pattern: emp{N}Name, emp{N}Age, emp{N}Dept, emp{N}Salary -->
  </tbody>
</table>

Task:

  1. Navigate to https://testkru.com/Elements/Tables
  2. Get the name of employee 1 (John Smith)
  3. Get the department of employee 3 (Sales)
  4. Get the salary of employee 4 ($85,000)

Expected output:

Employee 1 Name: John Smith
Employee 3 Dept: Sales
Employee 4 Salary: $85,000