public function getElementPositionByText(string $text, string $selector, string $textSelector = null, TraversableElement $baseElement = null): int
    {
        $baseElement = $baseElement ?? $this->getSession()->getPage();
        $counter = 0;

        $elements = $this->findAllElements($selector, $baseElement);
        foreach ($elements as $element) {
            ++$counter;
            if ($textSelector !== null) {
                try {
                    $elementText = $this->findElement($textSelector, 10, $element)->getText();
                } catch (\Exception $e) {
                    continue;
                }
            } else {
                $elementText = $element->getText();
            }
            if ($elementText === $text) {
                return $counter;
            }
        }

        return 0;
    }
public function getElementPositionByText(string $text, string $selector, string $textSelector = null, TraversableElement $baseElement = null): int
    {
        $baseElement = $baseElement ?? $this->getSession()->getPage();
        $counter = 0;

        $elements = $this->findAllElements($selector, $baseElement);
        foreach ($elements as $element) {
            ++$counter;
            if ($textSelector !== null) {
                try {
                    $elementText = $this->findElement($textSelector, 10, $element)->getText();
                } catch (\Exception $e) {
                    continue;
                }
            } else {
                $elementText = $element->getText();
            }
            if ($elementText === $text) {
                return $counter;
            }
        }

        return 0;
    }
public function getElementPositionByText ( string $ text , string $ selector , string $ textSelector = null , TraversableElement $ baseElement = null ) : int { $ baseElement = $ baseElement ?? $ this -> getSession ( ) -> getPage ( ) ; $ counter = 0 ; $ elements = $ this -> findAllElements ( $ selector , $ baseElement ) ; foreach ( $ elements as $ element ) { ++ $ counter ; if ( $ textSelector !== null ) { try { $ elementText = $ this -> findElement ( $ textSelector , 10 , $ element ) -> getText ( ) ; } catch ( \ Exception $ e ) { continue ; } } else { $ elementText = $ element -> getText ( ) ; } if ( $ elementText === $ text ) { return $ counter ; } } return 0 ; }
Finds an HTML element by class and the text value and returns it's position in order. Search can be narrowed to children of baseElement.

@param string $text Text value of the element
@param string $selector CSS selector of the element
@param string $textSelector Extra CSS selector for text of the element
@param TraversableElement|null $baseElement

@return int
Finds an HTML element by class and the text value and returns it s position in order . Search can be narrowed to children of baseElement .