[英]Different element is receiving the click, even though Xpath is correct and unique(Protractor)
我有以下两个要素
Xpath-> //sprk-accordion-item[@ng-reflect-title="Property"]//sprk-icon
Xpath-> //sprk-accordion-item[@ng-reflect-title="Repair"]//sprk-icon
我用来单击元素的代码
public async click(webElement: ElementFinder) {
try {
this.expectConditions.waitForElementToBeVisible(webElement);
this.moveToElement(webElement);
await webElement.click();
} catch (error) {
console.log('Error while clicking the element' + webElement.locator().toString() + 'Error:: ' + error);
}
}
public async waitForElementToBeVisible(element: ElementFinder) {
const ec = protractor.ExpectedConditions;
await browser.wait(ec.visibilityOf(element), this.time, 'Unable to find the element' + element.locator().toString());
}
public async moveToElement(webElement: ElementFinder) {
await browser.actions().
mouseMove(webElement).
perform();
}
click(element(by.xpath('//sprk-accordion-item[@ng-reflect-title="Property"]//sprk-icon'));
我的问题是,如果我运行测试大约10次
4次测试按预期运行。 当我尝试单击属性元素时,属性元素正在接受点击。
4次测试未按预期运行。 当我尝试单击属性元素时,即使我什至没有编写任何代码来单击修复元素,修复元素也都获得了点击。
2次没有任何元素获得点击。
没有焦点问题,因为在单击代码中,我将在单击元素之前移到该元素。 我使用的x路径是唯一的,它们甚至不是动态的。
当我放置browser.sleep(1000);
在单击属性元素之前,它已按预期单击。 不过,如果这是时间问题,应该说找不到该元素。 但是,当定位符唯一时,如何单击“修复”元素?
希望有人回答这个问题。
提前致谢
您错过了几个await
:
public async click(webElement: ElementFinder) {
try {
await this.expectConditions.waitForElementToBeVisible(webElement);
await this.moveToElement(webElement);
await webElement.click();
} catch (error) {
console.log('Error while clicking the element' + webElement.locator().toString() + 'Error:: ' + error);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.