A
A
Andrey2019-07-10 20:05:10
Software testing
Andrey, 2019-07-10 20:05:10

How to get text from Text element in Appium for React Native?

In the element component:

<Text {...setTestId('textTest')}>мне нужен этот текст</Text>

Seeking:
const firstHtmlView = await client.$('~textTest');
        const text = await firstHtmlView.getText();
        console.log('text', text);

In console:
text textTest

Although I expect (and according to the documentation comes out) the string 'I need this text'
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2019-07-10
@f-end

Wasted almost a day on this issue. As usual, everything turned out to be banal:
the problem was in the setTestId function. As everyone probably knows, there is a problem with finding elements by testId on Android. And therefore it is searched for by accessibilityLabel.
Here is the function for the test environment, it returned such an object for me: I installed both. I do not mind. And it turned out it was necessary to put only one desired value. Like this:

return Platform.OS === 'android'
            ? { accessible: true, accessibilityLabel: id }
            : { testID: id };

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question