[这是我的代码,我试图验证exit_without_save
是否显示在屏幕上,它是否与exit_without_save
交互,在这种情况下单击,但它仅向我显示它找不到该元素的错误。我做对了吗?
var new_button = browser.element(by.xpath('xpath'));
var exit_without_save = browser.element(by.xpath('xpath'));
await new_button.click();
if(await exit_without_save.isDisplayed()) {
await exit_without_save.click();
browser.sleep(500);
}
if(await (exit_without_save.isDisplayed())==true) {
await exit_without_save.click();
browser.sleep(500);
}
isDisplayed()
方法假定该元素已经在页面中呈现。您需要先等待它的出现。尝试这样的事情:var EC = protractor.ExpectedConditions;
var new_button = browser.element(by.xpath('xpath'));
var exit_without_save = browser.element(by.xpath('xpath'));
await new_button.click();
if (await exit_without_save.isPresent()) {
await browser.wait(EC.visibilityOf(exit_without_save));
return await exit_without_save.click();
}