我正在尝试删除应用中的一些重复的联系人(CafeTownsend)。这些元素在转发器中,下面是我用来删除联系人的功能。它没有正确执行浏览器操作。
完整项目@ ProtractorTest
deleteAccount(account: Account): void {
this.LIST_CONTACT.filter((elem, index) => {
return elem.getText().then((text) => {
return (text == account.fname + ' ' + account.lname);
});
}).then((filteredAccounts) => {
console.log(filteredAccounts.length+" accounts are there with "+account.fname);
if (filteredAccounts.length !== 0) {
filteredAccounts.forEach((elem,index)=>{
console.log('About to delete the contact');
elem.click();
this.LNK_DELETE_CONTACT.click();
browser.switchTo().alert().accept();
});
}else{
console.error(new Error('No such contact to delete'));
}
});
}
TypeScriptProject>protractor ConvertedJSFiles\config\config.js
[09:23:57] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[09:23:57] I/launcher - Running 1 instances of WebDriver
Started
**********
2 accounts are there with Jimmy
About to delete the contact
About to delete the contact
.**
Pending:
1) Cintact creation should check if contact is created
Temporarily disabled with xit
2) Cintact creation should delete the selected contact
Temporarily disabled with xit
3 specs, 0 failures, 2 pending specs
Finished in 18.523 seconds
[09:24:39] I/launcher - 0 instance(s) of WebDriver still running
[09:24:39] I/launcher - chrome #01 passed
答案 0 :(得分:0)
我能够为此问题提供解决方法,如下所示。
deleteSingleAccount(account: Account): void {
let filteredAccounts = this.LIST_CONTACT.filter((elem, index) => {
return elem.getText().then((text) => {
return (text == account.fname + ' ' + account.lname);
});
})
filteredAccounts.count().then((count) => {
console.log(count+' is the new count')
for (let i = 1; i <= count; i++) {
filteredAccounts.get(count-i).click();
this.LNK_DELETE_CONTACT.click();
browser.wait(EC.alertIsPresent,3000);
browser.switchTo().alert().accept();
}
});
}