例如,給定鏈接的文本,檢索洞鏈接元素。水貂選擇器:任何方式來獲取內容的基礎內的元素?
我嘗試這樣做:
$page = $this->getSession()->getPage();
$page->find('content', 'Italiano');
但它說:
Selector "content" is not registered.
編輯:後檢查everzet的答案的鏈接我有這樣的:
$el = $page->find('named', array(
'content', $this->getMainContext()->getSession()->getSelectorsHandler()->xpathLiteral('Pound')));
$el->click();
但我得到這個關於click()
函數的錯誤:
When I choose "Pound sterling" #
MyFirm\FrontendBundle\Features\Context\CurrencyControllerContext::iChoose()
error:_click(_byXPath("(//html/./descendant-or-self::*[contains(normalize-space(.), 'Pound')])[1]")) TypeError: parent.tagName is undefined ([object HTMLHtmlElement],"A",1)@http://myfirm.localhost/s/spr/concat.js:3286 ([object HTMLHtmlElement],"A")@http://myfirm.localhost/s/spr/concat.js:3762 ([object HTMLHtmlElement])@http://myfirm.localhost/s/spr/concat.js:331 ([object HTMLHtmlElement],false,false,(void 0))@http://myfirm.localhost/s/spr/concat.js:708 ([object HTMLHtmlElement])@http://myfirm.localhost/s/spr/concat.js:478 ()@http://myfirm.localhost/s/spr/concat.js:3016 ()@http://myfirm.localhost/s/spr/concat.js:3016 @http://myfirm.localhost/s/spr/concat.js:2822
<a
href='/s/dyn/Log_getBrowserScript?href=null&n=3286'>Click for browser script
這是var_dump($el)
輸出的開頭:
object(Behat\Mink\Element\NodeElement)#438 (2) {
["xpath":"Behat\Mink\Element\NodeElement":private]=>
string(74) "(//html/./descendant-or-self::*[contains(normalize-space(.), 'Pound')])[1]"
和$el->getTagName()
輸出爲 'HTML'。
這是因爲我試圖點擊一些不是元素而只是內容的東西嗎?在這種情況下,有什麼方法可以從內容中獲取元素?
這對我不起作用 – delirehberi
我已經使用遍歷頁面文檔更新了這個答案,因爲它是目前爲止最有用的答案。 – Jimbo
非常感謝@Jimbo –