'Find the element at `xpath` in `xml_root` and assert
that its text is `text`.
`xml_root` is an etree XML element
`xpath` is an XPath string, such as `\'/foo/bar\'`
`text` is the expected text that the element should contain
If multiple elements are found, checks the first one.
If no elements are found, the assertion fails.'

def assert_has_text(self, xml_root, xpath, text, exact=True):

    element_list = xml_root.xpath(xpath)
    self.assertGreater(len(element_list), 0, ("Could    not    find    element    at    '%s'" % str(xpath)))
    if exact:
        self.assertEqual(text, element_list[0].text.strip())
    else:
        self.assertIn(text, element_list[0].text.strip())
