4

In registration form address field if it is empty application, message shows in red color.

How can I capture this?

1
  • 1
    Capture what? What do you want to verify/assert? The message shows up, its color, both? – Niels van Reijmersdal Apr 16 '15 at 10:51
5

Steps:

  • Open page with form
  • Leave fields empty
  • Submit form
  • Wait for message to appear with an Explicit wait
  • Assert message text and color are correct

You can use .GetCSSValue("color") on a webElement to get its color value.

For an example look at: https://stackoverflow.com/questions/19668893/getcssvalue-color-in-hex-format-in-selenium-webdriver

1

You need to provide more information to be given any particularly detailed answers, but essentially the test case would navigate to your form and clear any text from the address field (you may need to enter some text then clear text from the field depending on how your form works).

After this you should be able to see the application message, so you need to write a selector which matches this message, and then assert that the message text is as you expect it to be.

If you can provide the DOM of the page once the message is shown, and other useful info I can provide more information to help, otherwise this is about as much as I can say.

1

you can user "getcssvalue" in java to get css attributes of element. Below is example

 String headerColor = driver.findElement(By.xpath(".//*[@id='LoginName']/h1")).getCssValue("backgroud-color");
   Assert.assertEquals("some message", "#FFFFFF", headerColor);

OR

if(headerColor.contains(#FFFFFF)){
  System.Out.Print("Color Mathes");
}
else
 {
System.Out.Print("Color Mathes");
}

some time color code should be displayed in rga format eg: rgba(45, 45, 45, 1), so instead of #ffffff you have to use rgba(45, 45, 45, 1)

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.