2014-09-30 68 views
0

以下小黃瓜正常工作與貝哈特但是當我使用PhantomJS我得到下面When I follow "Profile"線錯誤時,下拉菜單上失敗:貝哈特工作正常,但PhantomJS試圖點擊

注:該元件是由自舉這麼一個下拉菜單它在點擊後切換。

錯誤

Exception thrown by (//html/.//a[./@href][(((./@id = 'Profile' or contains(normalize-space(string(.)), 'Profile')) or contains(./@title, 'Profile') or contains(./@rel, 'Profile')) or .//img[contains(./@alt, 'Profile')])] | .//*[./@role = 'link'][((./@id = 'Profile' or contains(./@value, 'Profile')) or contains(./@title, 'Profile') or contains(normalize-space(string(.)), 'Profile'))])[1] 
{"errorMessage":"Element is not currently visible and may not be manipulated","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"27","Content-Type":"application/json; charset=utf-8","Host":"localhost:5140","User-Agent":"Apache-HttpClient/4.3.4 (java 1.5)"},"httpVersion":"1.1","method":"POST","post":"{\"id\":\":wdc:1412065547042\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/5b7c0830-487b-11e4-adc0-a162f25e4a98/element/%3Awdc%3A1412065547042/click"}} 

小黃瓜:

When I follow "Profile" 
And I follow "Edit" 

HTML:

<ul class="nav navbar-nav navbar-right"> 
    <li class="dropdown"> 
     <a href="#" class="dropdown-toggle" data-toggle="dropdown">Profile <span class="caret"></span></a> 
     <ul class="dropdown-menu" role="menu"> 
      <li><a href="#">Show</a></li> 
      <li><a href="#">Edit</a></li> 
     </ul> 
    </li> 
</ul> 
+1

您可以在頁面上運行所示的XPath表達式,以查看它是否真的是唯一一次使用「Profile」並且選擇了正確的元素。輸入開發者工具控制檯:'$ x(「(// html /.// a [./@ hr ........」);' – 2014-09-30 08:55:41

回答

0

我發現原因和解決d如下圖所示。

使用Bootstrap時,菜單被壓扁,只有一個圖標出現,代表相同的菜單,這是響應式設計的正常行爲。現在一切正常,但是當PhantomJS運行時,它無法找到它正在尋找的文本。例如在我的情況下,「配置文件」菜單。

菜單,它總是能正常工作的原始狀態:

enter image description here

壓塌版本導致PhantomJS失敗後:

enter image description here

解決方案:

只需將窗口大小設置爲更大一些,以便測試時菜單不會被壓扁。您可以根據需要將屏幕尺寸從1024X768更改爲其他內容。

#symfony/src/Site/CommonBundle/Features/Context/FeatureContext.php 

/** 
* @BeforeStep 
*/ 
public function beforeStep() 
{ 
    $this->getSession()->resizeWindow(1024, 768, 'current'); 
}