Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get next sibling using cssContainingText in Protractor

Is it possible to get the next sibling by using by.cssContainingText()

Example: HTML code is like below:

<div ng-repeat="SomeNgRepeat" class="ng-scope">
    <div class="text-label" >SomeText</div>
    <div class="some-class">SomeValue</div>
</div>

Get element by using:

element(by.cssContainingText('div.text-label','SomeText'))

Now find the next sibling of the above element.

I know of css=form input.username + input way of finding the sibling. However, this is not working in my case!

I think 'chaining' can be used to achieve this, but don't know How!

Thanks, Sakshi

like image 513
Sakshi Singla Avatar asked Feb 16 '15 12:02

Sakshi Singla


People also ask

What is CSS next sibling selector?

CSS Next Sibling Selector matches all element that are only next sibling of specified element. This Selector identify by + (plus sign) between two selector element. Next sibling selected match only one element that are sibling of specified element.

What is the difference between child and adjacent sibling selectors?

Child Selector: The child selector selects all elements that are the immediate children of a specified element. Adjacent Sibling Selector: The adjacent sibling selector selects an element that is the adjacent siblings of a specified element.

How to identify next sibling of specified element in HTML?

This Selector identify by + (plus sign) between two selector element. Next sibling selected match only one element that are sibling of specified element. This syntax apply to match all <p> element that are only next sibling of specified <div> element.

What is the use of CSS selector in HTML?

It is used in HTML to make a web element’s layout and style beautifully. A CSS selector is a path pattern that can use the web element’s attributes to locate a web element on the web page. A CSS selector is more simpler and faster than XPath, especially in Internet Explorer.


1 Answers

What if you would get it in one go using by.xpath():

element(by.xpath('//div[@class="text-label" and . = "SomeText"]/following-sibling::div'))

Or, you can combine it with cssContainingText():

element(by.cssContainingText('div.text-label','SomeText')).element(by.xpath('following-sibling::div'))
like image 124
alecxe Avatar answered Nov 09 '22 23:11

alecxe