从表单元素中提取数据

时间:2014-09-04 16:36:52

标签: php selenium behat mink

如何从<strong id="reference">123</strong>获得123?

如下所示。

/**
 * @Then /^I check reference in database$/
 * @throws \Exception
 */
public function checkReferenceInDb()
{
    $session = $this->getSession();
    $page = $session->getPage();

    $element = $page->find('css', //I think I should do something here to process the page content);

    if (null === $element) {
        throw new \Exception(sprintf('Could not evaluate CSS element"));
    }

    $id = //123 should be assigned to this and I'll do the rest
}

1 个答案:

答案 0 :(得分:1)

您可以使用快捷方式findById()

$element = $page->findById('reference');

然后,使用getText()从元素中获取文本:

$id = $element->getText();