我有一个带有此类标题栏的HTML页面:
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul ng-if="navMap.main" class="nav navbar-nav ng-scope" ng-repeat="item in navMap.main">
<li ng-if="item.items && item.items.length > 0" class="dropdown ng-scope">
<a href="#" class="dropdown-toggle ng-binding" data-toggle="dropdown" role="button" aria-expanded="false">
<i ng-if="item.iconClass && item.iconClass !== ''" class="glyphicon glyphicon-file"></i>
Documentazione
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li ng-repeat="child in item.items" ng-class="{divider:child.divider, 'dropdown-section':child.section}" class="ng-scope">
<a ng-if="!child.section && !child.divider" href="#" ng-click="navigate(child)" class="ng-binding ng-scope">
Introduzione
</a>
</li>
</ul>
</li>
</ul>
<ul ng-if="navMap.main" class="nav navbar-nav ng-scope" ng-repeat="item in navMap.main">
<li ng-if="item.items && item.items.length > 0" class="dropdown ng-scope">
<a href="#" class="dropdown-toggle ng-binding" data-toggle="dropdown" role="button" aria-expanded="false">
Funzionalità
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li ng-repeat="child in item.items" ng-class="{divider:child.divider, 'dropdown-section':child.section}" class="ng-scope">
<a ng-if="!child.section && !child.divider" href="#" ng-click="navigate(child)" class="ng-binding ng-scope">
Nuovo Ordine
</a>
</li>
</ul>
</li>
</ul>
<ul ng-if="navMap.right" class="nav navbar-nav pull-right ng-scope">
<li ng-if="!item.items" ng-hide="item.items" class="ng-scope">
<a href="#" ng-click="navigate(item)" class="ng-binding"></a>
</li>
<li ng-if="item.items && item.items.length > 0" role="presentation" class="dropdown ng-scope" ng-repeat="item in navMap.right">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<span class="flag-icon flag-icon-it"></span>
<span class="ng-binding">Cambia</span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li nf-if="item.navigationMode.toUpperCase() === 'CHANGELOCALE'" ng-repeat="child in item.items" role="presentation" ng-class="{disabled: configuration.langId === child.locale } " class="ng-scope disabled">
<a href="" role="menuitem" tabindex="-1" ng-click="changeLanguage(child.locale)" class="ng-binding">Italiano</a>
</li>
</ul>
</li>
</ul>
</div>
我想建立一个Protractor测试,选择标题栏中包含的其中一个列表的特定项目。这些列表中的每个项目都会重定向到另一个html,只需单击它即可。我能够通过测试正确选择列表中的项目(我看,在调试模式下,选择正确的项目)但是当我使用Protractor的click()方法模拟点击时,没有任何反应。测试成功结束,但我没有看到重定向到所选页面。
此选择的示例代码是:
// Opens on Documentation Menu -> IT SUCCEEDS AND I SEE THE MENU OPENED
$$('li.dropdown:nth-child(1)').get(0).$('a:nth-child(1)').click();
// Choosing Introduction -> NOTHING HAPPENS
$$('li.dropdown:nth-child(1)').get(0).$('ul li:nth-child(2) a:nth-child(1)').click();
还有其他量角器的指令来模拟锚标签上的点击?我的代码或遗漏的东西有什么问题吗?
答案 0 :(得分:4)
尝试以这种方式接近:
ul
元素以打开列表代码:
$("#navbarCollapse").click();
// by link text
element(by.linkText("Documentazione")).click();
// or by partial link text
element(by.partialLinkText("Documentazione")).click();
还有其他一些尝试:
browser.executeScript("arguments[0].click();", elm.getWebElement());
点击“通过javascript”
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
移至元素,然后单击
browser.actions().mouseMove(elm).click().perform();