Reputation: 179
I need to access to a div with a ng-show directive WITHOUT using xpath
<div ng-show="my_error && dirty_field">
Custom error message.
</div>
I tried these but it doesn't work properly
element(by.css('[ng-show=my_error && dirty_field]'));
and
element(by.model('my_error && dirty_field'));
How can I do?
Upvotes: 1
Views: 2100
Reputation: 2109
You cab deal with the properties this way in doing protractor testing.
element.all(by.css('[ui-sref="about_us"]')).first();
element(by.css('[ng-click="clickme()"]')),
element(by.css('[ng-show*=show_me]'));
Upvotes: 0
Reputation: 473833
Just to add few points here.
First of all, you definitely need the quotes around the ng-show
value in this case:
element(by.css('[ng-show="my_error && dirty_field"]'));
This is because the value contains non-alphanumeric characters. See this related thread:
Also, I don't think you should use the dirty_field
part in your locator. This sounds like a more technical variable used in the form validation logic. I'd use the "contains" check instead to check the my_error
part only (note how I've removed the quotes in this case - the value is alphanumeric):
element(by.css('[ng-show*=my_error]'));
Also note that you can use the $
shortcut instead of element(by.css())
:
$('[ng-show*=my_error]');
Upvotes: 1