Question: I am trying to assert a text that's seen on a media gallery overlay page. All I want is for the code to verify if the text is present and if so, assets it matches the expected text. 

For some reason, I keep getting failed tests. Below is the code I have written in Visual Code:

```
let expSuccessARMessage = "See it in Your Space (Augmented Reality) is currently only available using an AR compatible Apple device (iOS 12 or above)."
let successARMessage = browser.getText(page.pageElements.arMessage);

console.log(successARMessage);
assert(successARMessage === expSuccessARMessage, 'Success message');

```

What am I missing here?

Answer: 
Not a magician, but you should be getting `browser.getText is not a function` error in the console, because the `getText()` method is defined inside the `element` object, not the `browser` object. Read the complete API log **[here](https://webdriver.io/docs/api/element/getText.html)**.

So your code should be:

```
let expectedText = "Your long text here"
let foundText = $(page.pageElements.arMessage).getText();
// Considering 'page.pageElements.arMessage' is a valid selector for targeted element

console.log(`Found the following text: ${foundText}`);
assert.equal(expectedText, foundText, 'This is actually the ERROR message');

```

---

I want to add to the answer that there can also be a `browser` object centric approach, using the **[webdriver](https://webdriver.io/docs/api/webdriver.html)** protocol API. Thus, our code becomes:

```
let expectedText = "Your long text here"
let elementObject = browser.findElement('css selector', page.pageElements.arMessage);
// Considering 'page.pageElements.arMessage' is a valid selector for targeted element
let foundText = browser.getElementText(elementObject.ELEMENT);

console.log(`Found the following text: ${foundText}`);
assert.equal(expectedText, foundText, 'This is actually the ERROR message');

```

---

The latter approach is obsolete IMHO, and the recommended approach for WebdriverIO v5 would be using **[$](https://webdriver.io/docs/api/browser/$.html)**, respectively **[$$](https://webdriver.io/docs/api/browser/$$.html)** (*element & elements*). But wanted to give you a broader perspective.
If you defined the element into object repository like:

```
get OtpDescriptionText () { return '//div[@class="otp-description"]'; }

```

In order to **console** or **assert/expect** that element you need to use like:

```
let elem1 = await $(RegistratonPage.OtpDescriptionText);
console.log(await elem1.getText());

```

or

```
await expect($(RegistratonPage.OtpDescriptionText)).toHaveTextContaining('We just need to check this phone number belongs to you.')

```

If you don't use $, error is thrown