I’m trying to select an element by text, but the actual text changes because it has the current time stamp in it. Is there is way to select it without doing a substring search on getAttributes()? I can’t use getAttributes because we will also be testing on android.
The select I’m using:
await expect(element(by.text("James has initiated the chatbot: ShallowFaqChatbot"))).toBeVisible();
The element:
{
hittable: true,
activationPoint: { x: 153.5, y: 14.75 },
normalizedActivationPoint: { x: 0.5, y: 0.5 },
elementFrame: { y: 9, x: 9, width: 307, height: 29.5 },
enabled: true,
elementBounds: { y: 0, x: 0, width: 307, height: 29.5 },
layer: '<CALayer: 0x600002b907c0>',
safeAreaInsets: { right: 0, top: 0, left: 0, bottom: 0 },
visible: true,
elementSafeBounds: { y: 0, x: 0, width: 307, height: 29.5 },
label: 'James has initiated the chatbot: ShallowFaqChatbot - 11:08 am',
className: 'RCTTextView',
frame: { y: 473, x: 34, width: 307, height: 29.5 },
text: 'James has initiated the chatbot: ShallowFaqChatbot - 11:08 am'
}
You can see that it has the attribute text with the text I’m looking for, however detox is unable to grab it because of the " – 11:08 am".
2
Answers
You can try using detox "and" matcher
For this you’ll have to set your element’s testID.
Now, let’s suppose your element’s
testID
issuper_text_field
If you want to check that this element contains a specific text like "something" you can use the following workaround:
Of course this workaround has its limitations and assumptions, but I hope it works for your case!
Unfortunately, Detox doesn’t support Regex matchers: https://github.com/wix/Detox/issues/1441.
The easiest fix here would be adding a
testID
to the element and matching on that.You would not need to use
.and
to do this match. Not an ideal solution, but sincetestID
would be hidden away, this should be a working solution for your case.