Home Ask Login Register

Developers Planet

Your answer is one click away!

Henno February 2016

How to verify that the table has been correctly sorted in Codeception?

How can I test that the order of the rows in an HTML table is correct, after "clicking" table column caption to sort the table?


Rodel Bernal February 2016

It should be something like this:

*Assuming that the table has only 1 column

$elements = $this->elements($this->using('xpath')->value("//div[@id='row']/div")); //identifying row element
$rows = count($elements); //count the number of rows

$unsortedrow = [];
$unsortedrows = []

for($count=0;$count<$rows;$count++){    // Get all values in Unsorted table

    $unsortedrow[$count] = $I->grabTextFrom('//div[@id='main_body']/div/div['.$count.']/div/strong'); // Get text from row
    array_push($unsortedrows, $unsortedrow[$count]); // push the value of row N to rows array


Note: $this->elements() and count() are proven working in selenium 2 but I don't know if it also does in codeception, according to some of the articles i've read seeNumberOfElements is the alternative for that.

Post Status

Asked in February 2016
Viewed 2,436 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life