Category Archives: Selenium in PHP

Working with tables in Selenium in PHP

In this topic, You will learn how to perform below operations on table using Selenium.

  1. Find total number of rows and columns in a table
  2. Read a value from the table cell
  3. Click on elements inside table cells

Finding total number of rows and columns in a table

  1. //table//tr – This XPATH can be used to get all tr elements inside the table. Note that if there are nested tables, it will get all nested tr elements as well. To get only immediate child tr elements, you will have to use children property which returns collection of child tr elements. Alternatively you can use “//table/tr” XPATH to find only immediate child tr elements. Note that we have used single / which means find only immediate children.
  2. //table//th -This XPATH can be used to find total number of columns in a table. Note that all column headings should be marked with th tag. Also note that if one th tag spans multiple columns, it will be counted only once.
  3. //table//tr[1]//td – This XPATH finds all td elements (table cells) in the first row of the table.  Note that all nested td elements will be found using this XPATH expression.