I've recently put together a function in protractor that I'd like to share:
function findChildElementByText(parentElement, tagName, textToSearch)
{
return parentElement.all(by.tagName(tagName))
.then((items) => {
items.map( item => {
item.getText().then(text => {
if (text === textToSearch){
return item;
}
});
});
});
}
Here's an example of how you can use this function to locate <option>
elements within a <select>
element:
let myitem = selectorHelpers.findChildElementByText(clientIdSelect, 'option', 'ExampleText');
myitem.click();
However, when I try to click on the element, I encounter the following error message:
Failed: myitem.click is not a function
Can someone help me modify this function so that it returns the correct item based on the text criteria and enables me to click on the element as illustrated in the example above?