量角器找不到具有 id 的元素

protractor can not find element with id

我正在使用量角器,我不明白为什么当我尝试通过 css 获取某些东西时它有效,但如果我尝试使用 id 获取它却不起作用。

btnLogin 行上的错误消息

TypeError: undefined is not a function

部分代码

browser.get('http://localhost:3000/#!/signin');
expect(element.all(by.css('.btn-social')).count()).toBe(2);
expect(element(by.id('btnLogin').count())).toBe(1);

如果我尝试在输入中做某事它会起作用

element(by.id('username')).clear().sendKeys('something');

html 按钮

<button id="btnLogin" class="btn btn-lg btn-primary btn-block" type="submit">Login</button>

我不知道我做错了什么:S

您在 ElementFinder 上调用 count() - element() 调用的结果。

相反,如果你真的想检查计数,你需要 element.all():

expect(element.all(by.id('btnLogin').count())).toBe(1);