How to fail the test a visible element displayed

If my app screen one field is not required, how to fail the test. Please give me any idea

Hello Sudhir,

As previously asked on the same topic please provide more info.

But “field is not required” or “finding a field fails and you want o fail the test” ?

what I am saying
you see the image I marked the change password button . in that page change password button is not required. then I need to fail the test on a visible element. How?

"in that page change password button is not required. " , Sorry I am not that clear with that statement. That is more of an application functionality . no ?

Please mention what action does not success at runtime then the failure you need.
Example if an element is not loaded then you might want fail. The you can do following
try {
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("// [@id=‘password’]"))); // Where password is the element in consideration
catch (Exception) {
You can then try catch then use the “Fail” function of the test framework you are using. (if thats what you mean by fail )

Above is typically used when element is not loaded but other use case you may have to use some other thing.