编程语言
首页 > 编程语言> > javascript – AngularJs量角器:幻灯片菜单中的元素不可见

javascript – AngularJs量角器:幻灯片菜单中的元素不可见

作者:互联网

我带着更多的Protractor Q& A回来了.所以,我在尝试查找幻灯片菜单中的元素时遇到了一个问题.

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">

以下是我尝试从此菜单中获取按钮的方法:

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()"]'));

量角器不喜欢并继续告诉我这个:

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'

任何人都可以向我提出我可能做错的建议吗?

解决方法:

在找到并单击子菜单之前,您需要打开菜单:

element(by.css('nav.menu > md-content')).click();
element(by.css('nav.menu > md-content > button[ng-click="logoff()"]')).click();

您可能还需要使用elementToBeClickable expected condition来等待子菜单变为可点​​击(需要量角器1.7或更高版本):

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();

标签:javascript,angularjs,testing,protractor,end-to-end
来源: https://codeday.me/bug/20190725/1528438.html