You can use example below to get the content of given element with ID.


FeatureContext.php


class FeatureContext extends MinkContext
{
/**
* Get content of element with the provided css id
*
* @Then /^The content of the element with id "([^"]*)" equals to "([^"]*)"$/
*
* @param $elementId ID attribute of an element
* @param $content Content
* @throws \InvalidArgumentException
*/
public function contentsAreEqual($elementId, $content)
{
$session = $this->getSession();
$page = $session->getPage();

$element = $page->findById($elementId);

if (null === $element) {
throw new \InvalidArgumentException(sprintf('Could not evaluate CSS: "%s"', $elementId));
}

$element_content = $element->getText();

if ($element_content == $content) {
$element->click();
}

throw new \InvalidArgumentException(sprintf('Could not evaluate CSS content: "%s"', $content));
}
}