检查元素是否存在的语法是什么?我需要检查元素是否存在,以便在我的测试中更进一步。如果元素不存在,我想执行一些其他操作。
这就是我正在尝试但语法在平静中不起作用:
import {Click, PerformsTasks, Task, step, Wait, Is} from "serenity-js/lib/screenplay-protractor";
import {ProductDetailPageMap} from "../interactions/element-mappings/ProductDetailPageMap";
import { Interaction, UsesAbilities, AnswersQuestions } from "serenity-js/lib/screenplay-protractor";
import { Target, Attribute, BrowseTheWeb } from "serenity-js/lib/screenplay-protractor";
import { ElementArrayFinder, ElementFinder, $$, browser } from "protractor";
export class AddItemToWishlist implements Task {
static called(): AddItemToWishlist {
return new AddItemToWishlist();
}
private parseSizeList(elements: ElementArrayFinder): any {
if (elements.isPresent()) {
Click.on(ProductDetailPageMap.addToWishlist)
} else {
Click.on(ProductDetailPageMap.removeFromWishlist)
browser.sleep(2000);
Click.on(ProductDetailPageMap.addToWishlist)
}
}
@step('{0} Add Item to the Wishlist')
performAs(actor: PerformsTasks): PromiseLike<void> {
return actor.attemptsTo(
//return
);
}
}
我不知道在回报中要添加什么?
答案 0 :(得分:0)
var logoutButton = element("//button[@type='submit']/span[.='Add to wishlist']");
logoutButton.isPresent().then(function (result) {
if (result) {
// Element IS PRESENT...DO SOMETHING
} else {
// Element IS NOT PRESENT...DO SOMETHING
};
});