我正在使用 Protractor ,我不明白为什么当我尝试通过 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);
关于javascript - Protractor 找不到具有 id 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33259186/