2014-09-04 68 views
1

如何從<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

您可以使用快捷findById()

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

然後,使用​​從一個元素獲取文本:

$id = $element->getText(); 
+0

謝謝。按預期工作。 – BentCoder 2014-09-04 19:49:46