我有以下Protractor / Angular脚本:
clickAppMenuIcon() {
var EC = protractor.ExpectedConditions;
var menuLayer = element(by.id('cdk-overlay-2'));
expect(menuLayer.isPresent()).toBe(true)
.then(function (){
console.log('menu Layer shows');
var menuGrid = element(by.css('.menu-grid'));
expect(menuGrid.isPresent()).toBe(true)
.then(function () {
console.log('menu-grid shows');
browser.executeScript('' +
'var zIndexElement0 = document.getElementById("app-container");' +
'zIndexElement0.style.zIndex = "-20";' +
'var zIndexElement1 = document.getElementById("cdk-overlay-2");' +
'zIndexElement1.style.zIndex = "20";'
);
menuGrid.click();
var menuIcon = element(by.css('a[title=Configuration]'));
expect(menuIcon.isPresent()).toBe(true)
.then(function() {
console.log("menu Icon is present");
menuIcon.click();
var routerLinkIcon = element.all(by.css('.material-icons'));
expect(routerLinkIcon.isPresent()).toBe(true)
.then(function (){
console.log("it's there");
routerLinkIcon.click();
// browser.wait(function (){
// expect(browser.driver.getCurrentUrl()).toEqual('http://10.22.1.68:8080/configuration');
// },5000);
expect(browser.driver.getCurrentUrl()).toEqual('http://10.22.1.68:8080/configuration');
});
});
});
});
}
适用于Angular HTML:
<mat-card _ngcontent-c8="" class="app-menu mat-card ng-star-inserted">
<div _ngcontent-c8="" class="menu-grid">
<a _ngcontent-c8="" title="NPW">
<i _ngcontent-c8="" class="material-icons">account_balance</i>
</a>
<a _ngcontent-c8="" title="Upload">
<i _ngcontent-c8="" class="material-icons">file_upload</i>
</a>
<a _ngcontent-c8="" title="Correlate">
<i _ngcontent-c8="" class="material-icons">share</i>
</a>
<a _ngcontent-c8="" routerlink="workspaces" title="Workspace" ng-reflect-query-params="[object Object]" ng-reflect-router-link="workspaces" href="/workspaces">
<i _ngcontent-c8="" class="material-icons">content_copy</i>
</a>
<a _ngcontent-c8="" title="Help">
<i _ngcontent-c8="" class="material-icons">help</i>
</a>
<a _ngcontent-c8="" title="Send Notification">
<i _ngcontent-c8="" class="material-icons">add_alert</i>
</a>
<a _ngcontent-c8="" routerlink="configuration" title="Configuration" ng-reflect-router-link="configuration" href="/configuration">
<i _ngcontent-c8="" class="material-icons">settings_applications</i>
</a>
</div>
</mat-card>
它在控制台中返回它找到它,然后它应该可以点击以将URL重定向到新的,但它似乎坐在那里什么都不做,除了返回这个错误:
**************************************************
* Failures *
**************************************************
1) ConfigNavCheck should navigate to Configuration page on click
- Failed: Element not clickable at point (450,676). Other element would receive the click: <div class="mat-button-ripple mat-ripple mat-button-ripple-round" ng-reflect-disabled="false" ng-reflect-trigger="[object HTMLButtonElement]" matRipple="" ng-reflect-centered="true"></div>
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z'
System info: host: 'A0000872', ip: '10.22.73.23', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_77'
Driver info: driver.version: unknown
Executed 1 of 1 spec (1 FAILED) in 20 secs.
[13:58:50] I/local - Shutting down selenium standalone server.
[13:58:50] I/launcher - 0 instance(s) of WebDriver still running
[13:58:50] I/launcher - internet explorer #01 failed 1 test(s)
[13:58:50] I/launcher - overall: 1 failed spec(s)
[13:58:50] E/launcher - Process exited with error code 1
如何将网页重定向到点击的链接。我们已经尝试过等待它超时了。我们还有一个更简单的版本,适用于Chrome和Firefox,但不适用于IE11。必须支持IE,因此这是必要的。
答案 0 :(得分:0)
我知道我会以这种方式做一些不好的评论,但它至少可以在I.E.,Chrome和Firefox中使用。
browser.executeScript( 'document.querySelector(\'[routerlink = “配置”] \ ')单击();');
现在,如果您在单击某个元素时遇到问题,而不是像我在许多量角器登录问题中看到的那样,您可以使用:
changeZindexById(zIndexLayer, level) {
console.log('zIndex level: ' + level);
browser.executeScript('' +
'var zIndexElement = document.getElementByID("' + zIndexLayer + '");' +
'zIndexElement.style.zIndex = "' + level + '";'
);
}
changeZindexByClass(zIndexLayer, level) {
console.log('zIndex level: ' + level);
browser.executeScript('' +
'var zIndexElement = document.getElementsByClassName("' + zIndexLayer + '");' +
'zIndexElement[0].style.zIndex = "' + level + '";'
);
}