public function getElementsByText($text, $tags = '*') { // what are we doing? $tag = $this->convertTagsToString($tags); $log = usingLog()->startAction("get '{$tag}' element with text '{$text}'"); // prepare the list of tags if (is_string($tags)) { $tags = array($tags); } // build up the xpath to use $xpathList = array(); foreach ($tags as $tag) { $xpathList[] = 'descendant::' . $tag . '[normalize-space(text()) = "' . $text . '"]'; $xpathList[] = 'descendant::' . $tag . '[normalize-space(string(.)) = "' . $text . '"]'; $xpathList[] = 'descendant::' . $tag . '/*[normalize-space(string(.)) = "' . $text . '"]/parent::' . $tag; // special cases if ($tag == '*' || $tag == 'input' || $tag == 'button') { $xpathList[] = 'descendant::input[normalize-space(@value) = "' . $text . '"]'; $xpathList[] = 'descendant::input[normalize-space(@placeholder) = "' . $text . '"]'; } } // get the possibly matching elements $elements = $this->getElementsByXpath($xpathList); // log the result $log->endAction(count($elements) . " element(s) found"); // return the elements return $elements; }