【问题标题】:Protractor with Typescript: Failed: Cannot read property 'presenceOf' of undefined带打字稿的量角器:失败:无法读取未定义的属性“presenceOf”
【发布时间】:2020-08-22 19:45:22
【问题描述】:

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

这是我的代码:

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

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

【问题讨论】:

  • 你需要导入像import { ExpectedConditions} from 'protractor';这样的ExpectedConditions
  • 谢谢@SudharsanSelvaraj,您的建议解决了我的问题。

标签: typescript protractor expected-condition


【解决方案1】:

试试这样:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-15
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    相关资源
    最近更新 更多