Search code examples
javascripttypescriptautomated-testsblurtestcafe

Blur an input field in testcafe


I'm attempting to blur an input field in testcafe but can't seem to find out how.

I can use t.pressKey( "tab" ); although I don't feel this way is very good.

Is there another way to achieve this?


Solution

  • TestCafe is intended to emulate real-user behavior. So, I think that pressing tab isn't a bad workaround to make the element lose its focus.

    If you do not want to emulate key pressing, you can emulate a click on some other element, which will lead to blur on your input.

    Of course, you can call the blur method of the input element using the ClientFunctions mechanism, but it will require some extra coding.