Select all matching elements in PHPUnit Selenium 2 test case Select all matching elements in PHPUnit Selenium 2 test case selenium selenium

Select all matching elements in PHPUnit Selenium 2 test case


Pavel, you can find guidance on how to select multiple elements here: https://github.com/sebastianbergmann/phpunit-selenium/blob/b8c6494b977f79098e748343455f129af3fdb292/Tests/Selenium2TestCaseTest.php

lines 92-98:

public function testMultipleElementsSelection(){    $this->url('html/test_element_selection.html');    $elements = $this->elements($this->using('css selector')->value('div'));    $this->assertEquals(4, count($elements));    $this->assertEquals('Other div', $elements[0]->text());}

(This file contains the tests for the Selenium2TestCase class itself, so it's great for learning about its capabilities)

Following this method, you could retrieve all elements with a certain class like this:

    $elements = $this->elements($this->using('css selector')->value('*[class="my_class"]'));

Hope this helps.


To select multiple elements by class, use:

$elements = $this->elements($this->using('css selector')->value('.my_class'));