I want to query on particular elements.
My structure for code is as below:
HTML
<ul class="main">
<li>...</li>
<li>...</li>
<li>
<ul class="to--exclude">
<li>...</li>
<li>...</li>
</ul>
</li>
<li>...</li>
...
</ul>
I want to test li's
presence inside 'mainclass but not for
li'swhich are inside
to-exclude` class.
The problem is if I use element(by.css('.main li'))
, it will locate all the li's
including the ones inside the to-exclude
class.
In Chrome's developer tools, I'm able to locate them exactly using JQuery's :not
or .not()
.
$('.main li').not('ul.to--exclude li')
// OR
$(".main li:not('ul.to-exclude li')");
While using it in protractor as
element(by.css('.main li').not('ul.to--exclude li'));
// OR
element(by.css(".main li:not('ul.to--exclude li')"));
The above code gives an error:
InvalidElementStateError: invalid element state: Failed to execute 'querySelectorAll' on 'Document': '.main li:not('ul.to--exclude li')' is not a valid selector.
How to accomplish the same in protractor. How to exclude some classes which are nested inside the parent locator class.
Thanks