I am looking for a way to conditionally change text content in my web project, but I'm facing a challenge since the conventional methods seem limited. The cssContainingText
function typically accepts string or regular expression values. Is there a workaround that would allow me to use it dynamically based on certain conditions?
The code snippet below serves as a demonstration of my scenario.
let text;
if (a){
text = 'John Doe is a name';
} else if (b) {
text = 'Hello world';
} else if (c) {
text = 'This is a whole new sentence';
} else {
text = 'Default text'
}
return <div className='my-text'>{text}</div>;
element(
by.cssContainingText(
'my-text',
["/*Insert logic for conditional*/", ],
// even something like, 'text' || 'text-2' || 'text-3'
),
);