Exclude failed page load when checking changes

A page I’m checking occasionally fails to load, but even when I exclude it from continuing using conditions, it’s considered to be changed when the page next loads properly.

For example, when the page fails to load, there is the text “No stories found”. Is there any way of not using that page for change reference when that text is found?

1 Like

@textuality thanks for sharing your use case. one of the ways is to validate a page’s content after the page has loaded is using one of assert or panic functions in a macro. the last step in the macro can be something like this:

panic(element_has_text(body, "No stories found"), E_ASSERT, "Page didn't load correctly")

a screenshot with a something similar shown in the app:

to get started with macro, please see https://distill.io/docs/web-monitor/macro-to-record-replay-actions/. cheers!

Thanks. I had some slight issues with the editor (seems to work differently on the record macro screen vs the edit screen), but I think I’ve got it sorted now.

Will try it out for a couple of days to see how it goes.

Sadly it appears to be failing with this error.

element_has_text failed.
frame.$eval: Execution context was destroyed, most likely because of a navigation

I’ve tried two versions of the macro.

[
  "panic",
  [
    "element_has_text",
    {
      "value": "html",
      "type": "css"
    },
    "No stories found"
  ],
  "E_ASSERT",
  "Page failed to load"
]

and

[
  [
    "element_has_text",
    {
      "value": "html",
      "type": "css"
    },
    "No stories found"
  ],
  "E_ASSERT",
  "Page failed to load"
]

does the macro have any other step before the check for panic?

That’s the entire contents of the macro (or at least in this case, 2 versions).

The page does have a wait duration of 5 seconds set, if that makes a difference.

the macro recorder auto-generates a wait_doc step. keep that step as is and then add panic as the second step. that should make it work. right now the element_has_text is being called even before the page has loaded.

This is what I have now, which isn’t crashing, but also isn’t detecting the No stories text.

[
  [
    "wait_doc",
    {
      "frame": 0
    }
  ],
  "panic",
  [
    "element_has_text",
    {
      "value": "html",
      "type": "css"
    },
    "No stories found"
  ],
  "E_ASSERT",
  "Page failed to load"
]

I’m not having much luck with the macro editor (it’s borderline useless), so if you could suggest changes I could make to the source code that would be helpful.