量角器:按属性值查找隐藏的输入元素

Ila*_*sda 7 protractor

如何查找和获取以下元素的值?

<input type="hidden" title="username" value="joe.doe">
Run Code Online (Sandbox Code Playgroud)

任何建议非常感谢.

Leo*_*cci 16

var userNameElm = $('input[title=username]');

it('is present but invisible', function() {
    expect(userNameElm.isPresent()).toBeTruthy();
    expect(userNameElm.isDisplayed()).toBeFalsy();
});

it('should have proper value attribute', function() {
    expect(userNameElm.getAttribute('value')).toEqual('joe.doe');
});
Run Code Online (Sandbox Code Playgroud)

  • 那不是jQuery,Protractor` $()`是`element(by.css())的别名` (10认同)