I've got a basic web payment form, which needs to be automately tested. The form contains five fields - email, card number, card month expiry, card year expiry and CVC code. Also, have two buttons - pay(with displayed amount and currency) and cancel. If all fields are populated correctly and press pay, the user is redirected to a payment confirmation page. If, for example, the email field isn’t populated and press pay button, a floating message appears below the email field and says: ‘Email field must be filled before proceed’. In a couple of seconds, this floating message disappears. In my manual test I just verify that after press pay button, this message appears.

But in an automation test, the message isn’t visible in the DOM of the page. My idea is to assert that after press pay button, the button is still displayed with amount and currency. Is this the best approach in this situation and are floating messages like this, the best way to display field validation errors to the user?

  • Why are you so sure that the element is not in the DOM? actually it is not possible. You can have the element in DOM but not see it on your display, but not vice versa. – Alexey R. Mar 18 '19 at 10:07
  • If it's a message that only appears for a short duration it may appear as if it's not in the DOM as you can't find it in the time it takes to (appear - Press F12 - Search). However it will be in there. You can pause it when it's on screen (stackoverflow.com/questions/17931571/…) – Klynt Apr 15 '19 at 10:08

You may have two goals:

1 - Check the the message is displayed when the button is pressed:

In this case, you would have to wait to the message to assert afterwards

WebElement message = driver.findElement(...);

new WebDriverWait(driver, timeout).until(

assertEquals(message.getText(), "blablabla");

2 - You simply want to check the text of the message, but don't care/want to validate the displaying behavior:

In this case, you may either do it as a component check at your frontend or you can extract it by fetch the textContent attribute:

WebElement message = driver.findElement(...);
assertEquals(message.getAttribute("textContent"), "blablabla");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.