Anyone any idea about how to verify alert which is present on modal
dialog popup??? I tried command like selenium.isalertPresent() and driver.switchto().alert() but no luck. Is this bug?? |
Administrator
|
This looks confusing - " alert which is present on modal dialog"
Are you just referring to alert here? Also do you encounter any error when you use switch To?
~ seleniumtests.com
|
"Alert present on modal dialog"----when you clicked on links which is open popup window using window.open or window.showmodaldialog for opening popup.
if popup open with window.open then window().alert() working fine for handling alert present on it. but if popup open with window.showmodaldialog then window().alert() is not working with alerts on popup and console print noalertpresent exception. |
Hi tarun...... still waiting for your response regarding the same....
|
Administrator
|
Sorry mhans, but I am not sure of solution. I could have tried more if I had access to application.
~ seleniumtests.com
|
hey tarun u need not to feel sorry......on skype conversation u suggested me to use robot class to get alerts....i used the same class and got positive result but i want to verify these alerts for validate mandatory fields.
u know tarun i m much sure this is still a bug in selenium. |
Administrator
|
then I would suggest to file it here with all relevant details
~ seleniumtests.com
|
Selenium version--2.22
OS--Window(XP,7)i tried on both. browser--IE 7,8,9 language--java webdriver code--- String currentWindowHandle =driver.getWindowHandle(); System.out.println(currentWindowHandle); driver.findElement(By.cssSelector("#employmentGrid > thead.WhiteBk > tr > td.SectionHead > span > a")).click(); java.util.Set<String> availableWindows =driver.getWindowHandles(); System.out.println(availableWindows.size()); int Windows = 2; if (availableWindows.size()==Windows) { String popUpWindowHandle = null; for (String windowHandle2 : availableWindows) { if(!availableWindows.equals(currentWindowHandle)) popUpWindowHandle= windowHandle2; driver.switchTo().window(popUpWindowHandle); System.out.println(driver.getTitle()); driver.findElement(By.name("submit")).click(); Alert alt= driver.switchTo().alert(); System.out.println(alt.getText()); alt.accept();}}} Modal Dialog source-- <HTML> <HEAD> <div id="ContextMenu" style="{display: none; z-index:99999; position:absolute;}"> Cut Copy Paste</div> <iframe id="contextFrame" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;"></iframe> <script language="javascript" src="Javascript/Global.js"></script> <script language="javascript" src="Javascript/wz_tooltip.js"></script> <script language="javascript" src="Javascript/jquery-1.4.2.js"></ script> <script type="text/javascript" src="Javascript/jquery.tablesorter.js"> </script> <LINK rel="stylesheet" href="theme/jquery-ui-1.8.5.custom.css" type="text/css" /> <script Language="javascript" src="Javascript/jquery- ui-1.8.5.custom.js"></script> <script Language="javascript" src="Javascript/Menu.js"></script> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <META name="GENERATOR" content="IBM Software Development Platform"> <META http-equiv="Content-Style-Type" content="text/css"> <META http-equiv="expires" content="Thu May 31 12:44:29 EDT 2012"> <META http-equiv="no-cache"> <TITLE> Add Employment History</TITLE> <LINK href="theme/Master.css" rel="stylesheet" type="text/css"> <LINK rel="stylesheet" href="css/alternative.css" type="text/css" /> <script language="javascript" src="Javascript/StrutsValidation.js"></ script> </HEAD> <BODY scroll="no" onresize='sizeTiles(false, true)' onload='setDivParam("pagename.addemploymenthistory", true, false)' onBeforeUnload="return doUnload();" onmousemove="moveProcessing(event)" onContextMenu="return false;"> <script> //start the session timer sessionTimeOutMins=7200/60; dblMinutes = 115; setSessionTimeOutAlertTimer(); document.onkeydown = disableCtrlN; showProcessingWheel (); document.onreadystatechange = stopProcessing; //document.onmousemove = moveProcessing; function stopProcessing(){ hideProcessingWheel (); } </script>
<DIV class="divText">Click on the links below to perform any of the listed operations for this producer</DIV> <br> </DIV> <DIV id="masterDiv" style='overflow: auto;'> <form name="employmentBean" method="post" action="/PCRMVERSIONPREVIEW/ employmentHistoryAction.do" onsubmit="return submitPopupForm(this)"> <input type="hidden" name="mode" value="1"> <input type="hidden" name="actionMode" value="2"> <input type="hidden" name="formId" value="0"> <input type="hidden" name="licenseeId" value=""> <input type="hidden" name="parentBean" value="maintainProducer"> <input type="hidden" name="appliedEmployment" value="false"> <input type="hidden" name="appliedEmpProfile" value="true">
<input type="hidden" name="addressBean.addressId" value=""> <input type="hidden" name="addressBean.licensedEntityId" value=""> <input type="hidden" name="addressBean.entityType" value="EMP"> <input type="hidden" name="addressBean.addressTypeCode" value="EMP">
<script> var curr_year =''+2012+''; var curr_month =''+05+''; function compareTwoDates(startDate, endDate, message) { var fromDate = startDate.value; var toDate = endDate.value; if( (toDate != "" && toDate.length > 0) && (fromDate == "" || fromDate.length == 0) ){ alert("From Date field cannot be blank"); return false; } if( (fromDate!= "" && fromDate.length > 0) && ((toDate == "" || toDate.length == 0) && document.forms[0].currentEmployer.checked == false) ){ alert("To Date field cannot be blank"); return false; } if( document.forms[0].currentEmployer.checked && (fromDate == "" || fromDate.length == 0) ){ alert("From Date field cannot be blank"); return false; } startDateV = Date.parse(fromDate); endDateV = Date.parse(toDate); diff = (startDateV - endDateV)/(24*60*60*1000); if (diff > 0) { alert(message); return false; } return true; } function updateHiddenFields(frm) { var startDateYear = frm.elements["startDateYear"].value; var endDateYear = frm.elements["endDateYear"].value; var startDateMonth = frm.elements["startDateMonth"].value; var endDateMonth = frm.elements["endDateMonth"].value; if(startDateYear > 0 && startDateMonth > 0) frm.elements["startDate"].value=startDateMonth+"/01/"+startDateYear; else frm.elements["startDate"].value=""; if(endDateYear > 0 && endDateMonth > 0) frm.elements["endDate"].value=endDateMonth+"/01/"+endDateYear; else frm.elements["endDate"].value=""; } function dateRangeValidation(field){ var strValue=field.value; for(var j=0; j < strValue.length; j++) { if (strValue.charCodeAt(j) < asciiNumberZero || strValue.charCodeAt(j)> asciiNumberNine) { result = setFocusOnObjectWithMessage("Only Numeric values from 1900 to "+curr_year+" are allowed.", field) return true; } } return false; } function validateYear(fld,fldName){ if(fld.value > curr_year || fld.value < 1900){ alert(fldName+" range should be between 1900 to "+curr_year+"."); fld.focus(); return true; } return false; } function dateValidation(frm){ var startDateMonth = frm.elements["startDateMonth"].value; var startDateYear = frm.elements["startDateYear"].value; if(startDateMonth.length < 1 && startDateYear.length > 0) { alert("Please select the From month"); frm.elements["startDateMonth"].focus(); return true; } if(startDateYear.length < 1 && startDateMonth.length > 0) { alert("Please provide the From Year"); frm.elements["startDateYear"].focus(); return true; } var endDateMonth = frm.elements["endDateMonth"].value; var endDateYear = frm.elements["endDateYear"].value; if( frm.currentEmployer.checked==false) { if(endDateMonth.length < 1 && endDateYear.length > 0) { alert("Please select the End month"); frm.elements["endDateMonth"].focus(); return true; } if(endDateYear.length < 1 && endDateMonth.length > 0) { alert("Please provide the End Year"); frm.elements["endDateYear"].focus(); return true; } } if(startDateYear.length > 0 && (dateRangeValidation(frm.elements["startDateYear"]) || validateYear(frm.elements["startDateYear"],"Start Date"))) { return true; } if( frm.currentEmployer.checked==false) { if(endDateYear.length > 0 && (dateRangeValidation(frm.elements["endDateYear"]) || validateYear(frm.elements["endDateYear"],"End Date"))) { return true; } } if((frm.currentEmployer.checked==true) && (frm.elements["startDate"].value == null || frm.elements["startDate"].value.lengh == 0) ){ alert("From Date field cannot be blank"); return true; } if(startDateYear==curr_year && parseInt(startDateMonth, 10)>curr_month) { alert("From Date should not be greater than Today's Date"); return true; } if(endDateYear==curr_year && parseInt(endDateMonth,10)>curr_month) { alert("To Date should not be greater than Today's Date"); return true; } return false; } function preSubmitPopupForm(frm) { var parentWindow = window.dialogArguments.opener; var mandFields = parentWindow.document.forms[0].elements["mandFields"]; var mandFieldMsg = parentWindow.document.forms[0].elements["mandFieldMsg"]; var msgKeyValue = new Array(); if(mandFieldMsg){ var splitArray = mandFieldMsg.value.split(","); for(var i=0;i<splitArray.length;i++){ var splitPipeArray = splitArray[i].split("|"); msgKeyValue[trim(splitPipeArray[0])] = splitPipeArray[1]; } } if(dateValidation(frm)){ return false; } var appliedEmployment = frm.elements["appliedEmployment"].value; var appliedEmpProfile = frm.elements["appliedEmpProfile"].value; if(appliedEmpProfile=='true'){ appliedEmployment = appliedEmpProfile; } var countryCode; if(frm.elements["addressBean.countryCode"]){ countryCode = frm.elements["addressBean.countryCode"].value; } if(frm.elements["countryCode"]){ countryCode = frm.elements["countryCode"].value; } if(appliedEmployment=='true'){ if(frm.elements["addressBean.countryCode"]){ if(countryCode != 'US' && validateFormMandatory(frm, new Array("employerName","positionHeld","startDateMonth","startDateYear"), new Array("Please provide an Employer name","Please provide position held","Please provide From Month","Please provide From Year")) && ! dateValidation(frm)) { if( frm.currentEmployer.checked==false) { if(validateFormMandatory(frm, new Array("endDateMonth","endDateYear"), new Array("Please provide To Month","Please provide To Year")) && !dateValidation(frm)){ if(!compareDateFields(frm, new Array("startDate"), new Array("endDate"), new Array("To Date must be greater than the From Date"))) return false; } else return false } return validateFormMandatory(frm, new Array("addressBean.city","addressBean.countryCode"), new Array("Please provide city name","Please provide country name")) } if(countryCode == 'US' && validateFormMandatory(frm, new Array("employerName","positionHeld","startDateMonth","startDateYear"), new Array("Please provide an Employer name","Please provide position held","Please provide From Month","Please provide From Year")) && ! dateValidation(frm)) { if( frm.currentEmployer.checked==false) { if(validateFormMandatory(frm, new Array("endDateMonth","endDateYear"), new Array("Please provide To Month","Please provide To Year")) && !dateValidation(frm)){ if(!compareDateFields(frm, new Array("startDate"), new Array("endDate"), new Array("To Date must be greater than or equal to the From Date"))) return false; } else return false } var appliedEmpProfile = frm.elements["appliedEmpProfile"].value; if(appliedEmpProfile=='true'){ return true; } return validateFormMandatory(frm, new Array("addressBean.city","addressBean.stateCode","addressBean.countryCode", "addressBean.zipCode"), new Array("Please provide city name","Please provide state name","Please provide country name","Please provide zip code")) } return false; } if(frm.elements["countryCode"]){ if(countryCode != 'US' && validateFormMandatory(frm, new Array("employerName","positionHeld","startDateMonth","startDateYear"), new Array("Please provide an Employer name","Please provide position held","Please provide From Month","Please provide From Year")) && ! dateValidation(frm)) { if( frm.currentEmployer.checked==false){ if(validateFormMandatory(frm, new Array("endDateMonth","endDateYear"), new Array("Please provide To Month","Please provide To Year")) && !dateValidation(frm)){ if(!compareDateFields(frm, new Array("startDate"), new Array("endDate"), new Array("To Date must be greater than or equal to the From Date"))) return false; } else return false } return validateFormMandatory(frm, new Array("city","countryCode"), new Array("Please provide city name","Please provide country name")) } var empFieldArray = new Array(); var empFieldMsgArray = new Array(); if(mandFields){ if(mandFields.value.match("empName")){ empFieldArray.push('employerName'); if(msgKeyValue.empName.length>0){ empFieldMsgArray.push(msgKeyValue.empName); } } }else{ empFieldArray.push('employerName'); empFieldMsgArray.push("Please provide an Employer name."); } if(mandFields){ if(mandFields.value.match("empPositionHeld")) { empFieldArray.push('positionHeld'); if(msgKeyValue.empPositionHeld.length>0){ empFieldMsgArray.push(msgKeyValue.empPositionHeld); } } }else{ empFieldArray.push('positionHeld'); empFieldMsgArray.push("Please provide position held."); } if(mandFields){ if(mandFields.value.match("empFromMonth")){ empFieldArray.push('startDateMonth'); if(msgKeyValue.empFromMonth.length>0){ empFieldMsgArray.push(msgKeyValue.empFromMonth); } } }else{ empFieldArray.push('startDateMonth'); empFieldMsgArray.push("Please provide From Month."); } if(mandFields){ if(mandFields.value.match("empFromYear")){ empFieldArray.push('startDateYear'); if(msgKeyValue.empFromYear.length>0){ empFieldMsgArray.push(msgKeyValue.empFromYear); } } }else{ empFieldArray.push('startDateYear'); empFieldMsgArray.push("Please provide From Year."); } //var empFieldArray = new Array("employerName","positionHeld","startDateMonth","startDateYear"); //var empFieldMsgArray = new Array("Please provide an Employer name","Please provide position held","Please provide From Month","Please provide From Year"); if(countryCode == 'US' && validateFormMandatory(frm, empFieldArray, empFieldMsgArray) && !dateValidation(frm)) { if( frm.currentEmployer.checked==false){ var empFieldArray1 = new Array(); var empFieldMsgArray1 = new Array(); if(mandFields){ if(mandFields.value.match("empToYear")) { empFieldArray1.push('endDateYear'); if(msgKeyValue.empToYear.length>0){ empFieldMsgArray1.push(msgKeyValue.empToYear); } } }else{ empFieldArray1.push('endDateYear'); empFieldMsgArray1.push("Please provide To Year."); } if(mandFields){ if(mandFields.value.match("empToMonth")){ empFieldArray1.push('endToMonth'); if(msgKeyValue.empToMonth.length>0){ empFieldMsgArray1.push(msgKeyValue.empToMonth); } } }else{ empFieldArray1.push('endToMonth'); empFieldMsgArray1.push("Please provide To Month."); } if(validateFormMandatory(frm, empFieldArray1, empFieldMsgArray1) && !dateValidation(frm)){ if(!compareDateFields(frm, new Array("startDate"), new Array("endDate"), new Array("To Date must be greater than or equal to the From Date"))) return false; } else return false } var empFieldArray2 = new Array(); var empFieldMsgArray2 = new Array(); if(mandFields){ if(mandFields.value.match("empCity")){ empFieldArray2.push('city'); if(msgKeyValue.empCity.length>0){ empFieldMsgArray2.push(msgKeyValue.empCity); } } }else{ empFieldArray2.push('city'); empFieldMsgArray2.push("Please provide city name."); } if(mandFields){ if(mandFields.value.match("empState")){ empFieldArray2.push('stateCode'); if(msgKeyValue.empState.length>0){ empFieldMsgArray2.push(msgKeyValue.empState); } } }else{ empFieldArray2.push('stateCode'); empFieldMsgArray2.push("Please provide state name."); } if(mandFields){ if(mandFields.value.match("empCountry")){ empFieldArray2.push('countryCode'); if(msgKeyValue.empCountry.length>0){ empFieldMsgArray2.push(msgKeyValue.empCountry); } } }else{ empFieldArray2.push('countryCode'); empFieldMsgArray2.push("Please provide country name."); } empFieldArray2.push('zipCode'); empFieldMsgArray2.push("Please provide zip code"); return validateFormMandatory(frm, empFieldArray2, empFieldMsgArray2); } } } else { if(validateFormMandatory(frm, new Array("employerName"), new Array("Please provide an Employer name"))) { return compareDateFields(frm, new Array("startDate"), new Array("endDate"), new Array("To Date must be greater than or equal to the From Date")); } /*if(validateFormMandatory(frm, new Array("employerName"), new Array("Please provide an Employer name"))) { if( frm.currentEmployer.checked==false && appliedEmployment==true) { if(validateFormMandatory(frm, new Array("endDateMonth","endDateYear"), new Array("Please provide To Month","Please provide To Year")) && !dateValidation(frm)) { return compareDateFields(frm, new Array("startDate"), new Array("endDate"), new Array("To Date must be greater than or equal to the From Date")); } return false; } return true; }*/ } /*if(appliedEmployment=='true' && countryCode != 'US' && validateFormMandatory(frm, new Array("employerName","positionHeld","employmentAddress.city","employmentAdd ress.countryCode","startDateMonth","startDateYear","endDateMonth","endDateY ear"), new Array("Please provide an Employer name","Please provide position held","Please provide city name","Please provide country name","Please provide From Month","Please provide From Year","Please provide To Month","Please provide from To Year")) && !dateValidation(frm)){ return compareDateFields(frm, new Array("startDate"), new Array("endDate"), new Array("To Date must be greater than or equal to the From Date")); } else if(appliedEmployment=='true' && validateFormMandatory(frm, new Array("employerName","positionHeld","employmentAddress.city","employmentAdd ress.stateCode","employmentAddress.countryCode","startDateMonth","startDate Year","endDateMonth","endDateYear"), new Array("Please provide an Employer name","Please provide position held","Please provide city name","Please provide state name","Please provide country name","Please provide From Month","Please provide From Year","Please provide To Month","Please provide from To Year")) && ! dateValidation(frm)){ return compareDateFields(frm, new Array("startDate"), new Array("endDate"), new Array("To Date must be greater than or equal to the From Date")); } else if(appliedEmployment=='false' && validateFormMandatory(frm, new Array("employerName"), new Array("Please provide an Employer name"))){ return compareDateFields(frm, new Array("startDate"), new Array("endDate"), new Array("To Date must be greater than or equal to the From Date")); }*/ return false; } function validateEndDate(frm){ if(frm.currentEmployer.checked){ var appliedEmployment = frm.elements["appliedEmployment"].value; if(frm.elements["appliedEmpProfile"]){ var appliedEmpProfile = frm.elements["appliedEmpProfile"].value; if(appliedEmpProfile=='true'){ appliedEmployment = appliedEmpProfile; } } if(appliedEmployment=='true'){ document.getElementById("toDateYes").style.display = 'none'; document.getElementById("toDateNo").style.display = 'block'; } frm.elements["endDateMonth"].value=""; frm.elements["endDateYear"].value=""; frm.elements["endDate"].value=""; frm.elements["endDateMonth"].disabled = true; frm.elements["endDateYear"].disabled = true; frm.elements["currentEmployer"].value="true"; }else { var appliedEmployment = frm.elements["appliedEmployment"].value; if(frm.elements["appliedEmpProfile"]){ var appliedEmpProfile = frm.elements["appliedEmpProfile"].value; if(appliedEmpProfile=='true'){ appliedEmployment = appliedEmpProfile; } } if(appliedEmployment=='true'){ document.getElementById("toDateYes").style.display = 'block'; document.getElementById("toDateNo").style.display = 'none'; } frm.elements["endDateMonth"].disabled = false; frm.elements["endDateYear"].disabled = false; frm.elements["currentEmployer"].value="false"; } } validateEndDate(document.forms[0]); updateHiddenFields(document.forms[0]); --></script> </DIV> </BODY> </HTML> |
Free forum by Nabble | Edit this page |