1

Im filling a registration form. After filling all the fields I click on register then I get a message which is hidden initially. So I'm trying since very long to locate that particular element.

But I'm not able to locate that element due to which that particular error is never caught and I cannot proceed.

Need you input guys. I've tried isDisplayed(), isEnabled() etc. None of them work. I've even worked on writing custom methods to handle this but that too isn't able to handle.

//isElementPresent is custom method written by me
//Appointment.PhoneNoMatch is the locator which I've stored in objectrepository

boolean phoneError = isElementPresent(Appointment.PhoneNoMatch);

if (phoneError==true)
{
    System.out.println("Phone No already exist");
    break;
}
else
{
    //Rest of the execution
}

public boolean isElementPresent(By by) throws Throwable {
try {
   List<WebElement> ele = driver.findElements(by);
   if (ele.size() > 0) {
   return true;
}
else
{
   return false;
}
}
catch (Exception e) 
{
System.out.println(e.getMessage());
return false;
}
}
Robert Dsilva
  • 81
  • 1
  • 2
  • 10

2 Answers2

0

It's created by the browser because your field has an HTML 5 required property set, and isn't an HTML / DOM element you can detect in the usual way. However, see this answer: https://stackoverflow.com/a/29548873/954442 for how to detect it using a CSS pseudo-selector.

If it's causing problems for your test, one suggestion would be to remove the property using JavaScript and fall back to testing the server side's validation, e.g. an HTTP error code.

See also: Chrome popup Please Fill Out this Field and Check if "Please enter an email address" message appears

Community
  • 1
  • 1
Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
  • Thanks for the help buddy! I tried myself and I got the solution. If you wish to see the solution I have posted it above. Thanks once again :) – Robert Dsilva Jan 28 '16 at 07:43
0

After breaking my head over a week for this problem I finally got the solution to it.

After all the possible things didn't work out I had to switch to getAttribute using which I got the class and then did a getText() and compared that text with the actual and displayed the error.

Using getAttribute I got the class and the thing that I noticed was that when there was some invalid entry or blank entry the class attribute changed to focused as the focus switched to that particular element.

//Appointment.EmailIDError is the locator which is stored in object repository
String ClassName1 = driver.findElement(Appointment.EmailIDError).getAttribute("class");
       if(ClassName1.equalsIgnoreCase("form-group label-floating has-error is-focused"))
         {
          System.out.println("Email ID is Inavalid type");
         }

If any further clarification needed then contact me

Robert Dsilva
  • 81
  • 1
  • 2
  • 10