0

我正在尝试使用量角器,打字稿等待元素存在。

这是我的代码:

import { browser, by, element } from 'protractor';
import { protractor } from 'protractor/built/ptor';

export class LoginPage {

    title = element(by.css('my-page > h3'));

    async openMyPage() {
        await browser.get(browser.baseUrl);
        await browser.wait(protractor.ExpectedConditions.presenceOf(this.title), 5000,
            "Title does not appear during 5 seconds")
    }
}

它失败并出现错误:Failed: Cannot read property 'presenceOf' of undefined

有人可以帮我理解这个原因吗?以及如何解决?谢谢

4

1 回答 1

0

试试这样:

import { browser, by, element, ElementFinder, protractor } from 'protractor';

export class NameofClass {

public title: ElementFinder;

constructor() {

this.title = element(by.css('my-page > h3'));
}

async openMyPage() {
        await browser.get(browser.baseUrl);
        await browser.wait(protractor.ExpectedConditions.presenceOf(this.title), 5000,
            "Title does not appear during 5 seconds")
    }
}
于 2020-05-07T17:40:12.107 回答