Reputation: 9084
Im having big problems trying to write my end2end testing.
This is my scenario: I want to count the number of options for a given element.
What I DONT want to do is to use id's, so Im trying to select it without polluting the html.
Lets see the html:
<form class="catalogue-sidebar">
...
<ki-multi-select-option>
<select>
...
<option></option>
...
</select>
</ki-multi-select-option><!-- ki-multi-select-option -->
...
</form><!-- .catalogue-sidebar -->
I have a few ki-multi-select-option directives here. I need to count lets say, the number of options on the second one.
How can I select it ?
Using id's will be something like this (this works):
var colorsOptions = browser.findElements( by.css( '#filter-colors select > option' ) );
colorsOptions.then( function( elements ) {
// There is an empty option as default, thats why "greater than 1"
expect( elements.length ).toBeGreaterThan( 1 );
});
But as I said, I want to avoid including ids just for testing.
I have tried lot of different combinations but without success.
Using jQuery I could do something like this:
$( ".catalogue-sidebar ki-multi-select-option:eq(1)" ).find( 'select > option' )
Anybody can help me here ?
Thanks !
Upvotes: 1
Views: 429
Reputation: 3691
Using just CSS:
var options = element.all(by.css('.catalogue-sidebar ki-multi-select-option:nth-child(1) select option'));
var kiWrapper = element.all(by.css('.catalogue-sidebar ki-multi-select-option')).get(1);
var options = kiWrapper.all(by.css('select option'));
Now with the count function there is no need of a then
since expect
handles webdriver promises:
expect(options.count()).toBeGreaterThan(1);
Upvotes: 2