gpt4 book ai didi

javascript - 等待带有定位器的元素时超时

转载 作者:行者123 更新时间:2023-11-28 05:19:54 26 4
gpt4 key购买 nike

我正在尝试测试以下代码:

<div name="userElem" *ngFor="let user of users ; let i=index">
<div class="list-group-item" id="user-{{i}}" (click)='selectUser(user)' [style.backgroundColor]="user?._id==selectedUser?._id ? '#F0F0EE' : 'white'">
<div *ngIf="user?._id==selectedUser?._id">
<div class="pull-right">
<a id="delete-user-{{i}}" (click)="deleteUser(user._id)">
<i class="fa fa-trash fa-fw"></i>
</a>
<a (click)="editUser(user._id)">
<i class="fa fa-pencil fa-fw"></i>
</a>
<a [routerLink]="['/edit',user._id]" name="userLink-{{i}}">
<i class="fa fa-eye fa-fw"></i>
</a>
</div>
</div>
</div>
</div>

通过使用以下 E2E 测试用例:

it('should delete a user', () => {
page.navigateToUserComponent();
let selectUserElem = element(by.id('user-0')).click(); //this event is fired as I can see user getting selected.
let deleteUserElem = element(by.id('delete-user-0'));
browser.wait(function() {
return browser.isElementPresent(by.id('delete-user-0'));
}, 5000);
expect(deleteUserElem.isPresent()).toBeTruthy(); // if element is present I want to click that element .i.e. delete the first user in array
});

但到目前为止还没有取得任何成功。

我尝试了此链接中讨论的多种方法:

StackOverflow Post

但无法使其工作。有什么帮助吗?

谢谢

最佳答案

如果您想识别第一个delete_user元素,您可以使用以下xpath。

let deleteUserElem = element.all(by.xpath(".//a[contains(@id, 'delete-user-')]")).first();

然后您可以将其与 Protractor 预期条件结合起来,等待所需的 Web 元素出现。

EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(deleteUserElem),20000, 'element is not visible within the time specified');

关于javascript - 等待带有定位器的元素时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40647576/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com