'locate element in protractor from multiline text

I have few webElements, which when converted to text return:

School, Primary School\n' +
Church, Catholic Church,

FireStation, Primary Station\n' +
Church, Catholic Church,

School, Primary School\n' +
FireStation, Primary Station,

They need to be located by 2 separate conditions, but I am unable to chain them. I am trying to locate the first element from list

School, Primary School\n' +
Church, Catholic Church,

by using:

element(by.cssContainingText('.given_class',`${interpolation[for_school]}`, `${interpolation[for_church]}`)).getText()

Nothing works. I have tried chaining locators

element(by.cssContainingText('.given_class',`${interpolation[for_school]}`)).element(by......`)).getText()

no luck

I have tried using few other methods, but nothing seems to work.

They all have the same class, id, type etc. They need to be found by text



Solution 1:[1]

use xpath and operator

element(by.xpath('//*[contains(text(),"locate element") and contains(text(),"from multiline text")]'))

you can try it on this page to locate questions header //*[contains(text(),"locate element") and contains(text(),"from multiline text")]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sergey Pleshakov