Selenium+PHPunit: foreach element in collection -


i looking way work collections of elements in selenium phpunit. let's have below code:

<div class="test">aaa</div> <div class="test">bbb</div> <div class="test">ccc</div> 

i able work on <div> elements inside each loop, let's selecting elements based on class //div[@class='test']

$divs = ...  //  foreach ($divs $div) {  // } 

in php, if want work html data, great solution using domdocument class -- means being able work dom methods -- via domdocument::loadhtml() method.


loading html domdocument :

$dom = new domdocument(); $dom->loadhtml('here html string'); 

you can instanciate domxpath object :

$xpath = new domxpath($dom); 


allow extract data html, using xpath queries, domxpath::query() :

$entries = $xpath->query('//div[@class='test']'); if ($entries->length > 0) {     foreach ($entries $entry) {         // work on $entry -- dom node/element     } } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -