PDA

View Full Version : VBA Close Java Alerts Popups with name "Message from webpage"



l_rosete22
08-06-2013, 01:42 AM
Hi All, Im having a problem dealing with the java scripts alerts..

I am able to navigate and enter data in the webpage but when selecting different item to update a modal alerts displayed..

How can I click the OK button tru VBA?

Any help please...

Here is the code in the webpage i think firing when i select an item triggering the alert..



function onUpdatedShowAlertTS(varControl) {


if (varControl == "ddlProjectStatus") {
var varconfirm = document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hd nReleaseStatusConfirmation');
if (varconfirm.value == "true") {
var varControlId = document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_dd lProjectStatus');
var value = varControlId.options[varControlId.selectedIndex].innerText;
alert('Release status is reset to ' + value + ' successfully and validation status is Pending.');
document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hd nReleaseStatusConfirmation').value = "false";
}
}


if (varControl == "ddlReleaseName") {
var varconfirm = document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hd nReleaseNameConfirmation');
if (varconfirm.value == "true") {
alert('Release status and and validation status is reset successfully.');
var isReadOnlyStatus = '0'
if (!(isReadOnlyStatus == 1)) {
document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hd nReleaseNameConfirmation').value = "false";
document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_bt nSaveValidate').disabled = false;
}
}
}


Im trying to intercept the alerts using the code below.. but it does not work.


ieDoc.getElementById("ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnConfirmationforReleaseCh ange").Click ieDoc.getElementById("ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnConfirmationforReleaseCh ange").setAttribute "value", "true"
ieDoc.getElementById("ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnConfirmationforReleaseCh ange").setAttribute "type", "hidde"

l_rosete22
08-09-2013, 03:29 AM
solved it by myself.. this code works afterall...




ieDoc.getElementById("ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_ddlReleaseName").selectedIndex = 1
'ieDoc.getElementById("ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_ddlReleaseName").FireEvent ("onchange")
Do While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy: TimeoutCheck: Loop
Sleep (3000)
apiShowWindow ie.hWnd, SW_SHOWNORMAL


Call ieDoc.parentWindow.execScript("window.confirm = function onUpdatedShowAlertTS(varControl) {return true}", "JavaScript")