問題描述
我帶著更多量角器問答回來了.因此,在嘗試查找滑出菜單內的元素時,我遇到了一個問題.
I'm back with more Protractor Q&A. So, I am coming across an issue when trying for find an element that is inside a slide out menu.
html片段:
<div class="ng-scope" ui-view="navmenu">
<nav class="menu slide-menu-left ng-scope">
<md-content class="md-default-theme" style="display: table" ng-click="slideMenuLeft()" tabindex="0">
<button class="md-button md-default-theme" ng-transclude=""
style="width:50%;height:72px;border-right:1px solid #ddd;border-bottom:1px solid #ddd"
ng-click="checkmap()" tabindex="0">
以下是我嘗試從該菜單中獲取按鈕的方法:
Here are the ways I have tried to grab the the button out of this menu:
element(by.css('Button[ng-click="logoff()"]'));
element(by.xpath('/html/body/section/div[@class="ng-scope"]/nav[@class="menu slide-menu-left ng-scope"]/md-content/button[@ng-click="logoff()"]'));
量角器不喜歡并繼續告訴我:
Protractor does not like and proceeds to tell me this:
Stacktrace:
ElementNotVisibleError: element not visible
(Session info: chrome=40.0.2214.115)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 31 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
任何人都可以就我可能做錯的事情向我提出建議嗎?
Can anyone throw me suggestions as to what I may be doing wrong?
推薦答案
在定位并點擊子菜單之前需要打開菜單:
You need to open up the menu before locating and clicking the submenu:
element(by.css('nav.menu > md-content')).click();
element(by.css('nav.menu > md-content > button[ng-click="logoff()"]')).click();
您可能還需要使用 elementToBeClickable
預期條件等待子菜單變為可點??擊(需要量角器 1.7 或更高版本):
You may also need to use a elementToBeClickable
expected condition to wait for the submenu to become clickable (needs protractor 1.7 or above):
var EC = protractor.ExpectedConditions;
var logoff = element(by.css('nav.menu > md-content > button[ng-click="logoff()"]'));
browser.wait(EC.elementToBeClickable(logoff), 10000);
logoff.click();
這篇關于AngularJs量角器:滑出菜單中的元素不可見的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!