# Synthetic Monitoring : Scripting in Detect Error Text

**URL:** <https://discuss.elastic.co/t/synthetic-monitoring-scripting-in-detect-error-text/361824>\
**Category:** Synthetics\
**Created:** [June 21, 2024, 6:51am UTC](https://discuss.elastic.co/t/synthetic-monitoring-scripting-in-detect-error-text/361824 "2024-06-21T06:51:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aisyaharifin](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@aisyaharifin](https://discuss.elastic.co/u/aisyaharifin)\
**Post date:** [June 21, 2024, 6:51am UTC](https://discuss.elastic.co/t/synthetic-monitoring-scripting-in-detect-error-text/361824/1 "2024-06-21T06:51:30Z")

</div>

Hi Elastic,

Need help on how can I create a script on my use case where, if we detect there is Error display in the page, we want to note it as Fail and not Complete as in success.

For example, below is the sample of error :

![Screenshot 2024-06-21 at 2.37.12 PM](https://us1.discourse-cdn.com/elastic/original/3X/9/3/93cf7ce4bc5069060b17b95b07a58861ebee33ec.png)

Below is the script that I create but its not working, it still showing as Success :

```auto
step('Error Checking', async () => {
  try{
    await page.goto('https:// ****.com');
    await page.locator('[placeholder="Search From Here"]').click();
    await page.locator('[placeholder="Search From Here"]').fill('test');
    await Promise.all([
      page.waitForNavigation(),
      page.locator('[placeholder="Search From Here"]').press('Enter')
    ]);
  }
  catch(e){
    await expect(page.getByText('Error', { exact: true })).toBeVisible();
    console.log("Closed the browser")
    await browser.close();
    throw e;
  }
});

```

I try to do the error checking by try and catch, but its not working.

It still detect as Complete :

 ![Screenshot 2024-06-21 at 2.45.17 PM](https://us1.discourse-cdn.com/elastic/original/3X/c/d/cd1251df93db76c133dc1826878fad71262c983a.png)

To give you context on the script, I want to check if user did the searching, for example if 'test' query has been input, will it throw error on whether the server is error.

Not sure if I did the correct way but the wording error text is within

 html tag.

Below is the inspect of the page :

 ![Screenshot 2024-06-21 at 2.36.05 PM](https://us1.discourse-cdn.com/elastic/original/3X/c/2/c2b2f72e4e91c4f4ba7c0ed197d6ec1fe62f43c9.png)

Need guidance on this thanks!

---

<div class="post-metadata">

**Author:** ![shahzad31](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahzad31/32/51637_2.png) [@shahzad31](https://discuss.elastic.co/u/shahzad31)\
**Post date:** [June 21, 2024, 7:19am UTC](https://discuss.elastic.co/t/synthetic-monitoring-scripting-in-detect-error-text/361824/2 "2024-06-21T07:19:10Z")

</div>

Hello @aisyaharifin ,

if you want the test to fail if certain locator is present on the page you can do an assertion like this

```auto
  step('launch application', async () => {
    await page.goto('https://www.google.com');
  });

  step('it fails if there is text', async () => {
    expect(await page.locator('text=Google').count()).toEqual(0);
  });

```

you can read more here

> <https://stackoverflow.com/questions/71183099/how-can-i-assert-that-an-element-is-not-on-the-page-in-playwright>

Best

---

<div class="post-metadata">

**Author:** ![aisyaharifin](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@aisyaharifin](https://discuss.elastic.co/u/aisyaharifin)\
**Post date:** [June 21, 2024, 7:21am UTC](https://discuss.elastic.co/t/synthetic-monitoring-scripting-in-detect-error-text/361824/3 "2024-06-21T07:21:11Z")

</div>

Hello @shahzad31 ,

Cool, thanks for the reference, let me try on this and get back to you if it still not working.

Thanks again!
