protractor icon indicating copy to clipboard operation
protractor copied to clipboard

By.model not working with select elements

Open willread opened this issue 12 years ago • 5 comments

with a template such as the following:

<select ng-model="foo" value="bar">
    <option value="bar">bar</option>
</select>

this test:

expect(element(by.model("foo")).getAttribute("value")).toEqual("bar");

will fail with the following error:

Error: JS locator script result was not a WebElement

where I would expect it to find the select element and the test to pass.

This appears to be a problem with select lists specifically, as similar tests will pass fine for non-select input elements.

willread avatar Dec 02 '13 22:12 willread

This is an issue with any non input elements.

For by.model function definition see

https://github.com/angular/protractor/blob/master/lib/locators.js#L112

And for the actual selector creation https://github.com/angular/protractor/blob/master/lib/clientsidescripts.js#L228

gingermusketeer avatar Dec 04 '13 05:12 gingermusketeer

What you want is element(by.select("foo"))

juliemr avatar Dec 04 '13 15:12 juliemr

It seems to me that the by.model selector should select anything with a ng-model attribute, at least that is the expected behaviour. Could we change the selector in clientsidescripts from input[...] to *[...] ?

gingermusketeer avatar Dec 04 '13 20:12 gingermusketeer

Yes, this should probably happen. I'm trying to think of any downsides - let me open a separate issue to get comments.

On Wed, Dec 4, 2013 at 12:00 PM, Max Brosnahan [email protected]:

It seems to me that the by.model selector should select anything with a ng-model attribute, at least that is the expected behaviour. Could we change the selector in clientsidescripts from input[...] to *[...] ?

— Reply to this email directly or view it on GitHubhttps://github.com/angular/protractor/issues/316#issuecomment-29839571 .

juliemr avatar Dec 04 '13 20:12 juliemr

Please continue discussion in #321

juliemr avatar Dec 04 '13 20:12 juliemr