angular-datetime
angular-datetime copied to clipboard
Selenium testing failing in Safari
I'm facing issues while sending Keys to the custom date field via Selenium.
I'm using a Work Around to send fields into the custom date format.. It does not work any other Way! This works on ALL browsers but facing Intermittent failures using Safari.
The Algo is..
- Split DD/MM/YYYY into Arr = [DD MM YYYY]
- Send 'a'
- Send the ith element of Arr[]
- Repeat 2 and 3.
Below is the Code snippet just to send date Keys.
public boolean sendDateKeys(By locator,String date, String msg1, String id, int index ) throws IOException{ //This is browser Sensitive
String msg2 = "Entered";
DebugPauseAfterStep();
String dob;
String srcFormat = "mm/dd/yy" ;
String dstFormat_all = "dd/mm/yyyy";
String elemDob = UtilFunctions.get().getAngVar(id);
System.out.println("the current date is "+ elemDob);
dob = UtilFunctions.convertDateFormat(date , srcFormat, dstFormat_all);
System.out.println("the converted date is "+ dob);
dob = UtilFunctions.convertDateFormat(CL.getTestDataInstance().getDOB(), srcFormat, dstFormat_all);
WebDriver wd = CL.GetDriver();
try {
UtilFunctions.sleepFor(1,"safari date field"); //TODO better is wait for value to be found..
wd.findElement(locator).sendKeys("a");
String currBoxVal = getAngVar(id);
System.out.println(String.format("the target is %s and orignal is %s", dob, currBoxVal));
int i = 0 ;
for (String s : dob.split("/")){
wd.findElement(locator).sendKeys(s);
if (isSafari()){
DebugPauseAfterStep();
wd.findElement(locator).sendKeys("a");
}
wd.findElement(locator).sendKeys("a");
i++;
}
myReport("Pass", msg1 + " " + msg2 + " Value is:"+ b(dob));
// UtilFunctions.get().sendKeys(locator, s, "Date of Birth", "Entered");
return true;
}catch(Exception e){
myReport("Fail", msg1 + " NOT" + msg2 + " Value is:" + b(dob) );
e.printStackTrace();
return false;
}
}
I don't use selenium either safari.
How about to add some delay before sending each key?