按精确的 HTML 属性值选择元素

要通过精确的 HTML 属性选择元素,请使用 css 定位器模式 [attribute = value]

//selects the first element with href value '/contact'
element(by.css('[href="/contact"]')); 

//selects the first element with tag option and value 'foo'
element(by.css('option[value="foo"]')); 

//selects all input elements nested under the form tag with name attribute 'email'
element.all(by.css('form input[name="email"]'));