Formik Fields Validation

Hi,
I have to verify the field in the form, that most likely is handled by Formik or some jQuery, idk, anyway, for empty fields or wrong email, there is an automatic fields validation, you saw it million times, pretty standard thing for forms. The warning is not a part of DOM, can’t find it anywhere in the code. I tried every keyword that could work, also JS to find it, with no success. How to grab/locate this element, to test if it appears, or if it shows the correct message?

Hi Paulina,

Normally these warning messages are not part of the dom until the validation has happened, usually they are inside a <div> or <span> element that gets created when the js validation detects an invalid field, though in some cases a page refresh happens and the whole form is send back with the warning message embedded into it.

either way, your best bet is to manually trigger the validation so the warning message is created, then use dev tools to find it in the dom, best case is if it’s created by js, then it’s probably inside another <div> that has a uniquely identifiable name, another way that you might be able to detect it is if there is a standard warning image, find the warning image element and use that as a reference point in your xpath to find the text.

Your script logic will probably be something like:

  • check if there is a warning
  • if warning
    • get warning text
    • log warning text
    • fail
  • else [optional]
  • log warning not found :+1:

If you need more help beyond that we’ll need to know what library you’re using and maybe an example form that can be accessed that behaves the same way your form does.

Hope that helps,

Dave.