1

检查元素是否存在的语法是什么?我需要检查该元素是否存在以便在我的测试中走得更远。如果该元素不存在,我想执行一些其他操作。

这就是我正在尝试的,但语法在平静中不起作用:

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 
        );
    }
}

我不确定要在退货中添加什么??

4

1 回答 1

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
        };
    });
于 2018-03-08T20:21:13.350 回答