Highlighted
Acclaimed Contributor.
Acclaimed Contributor.
398 views

[Knowledge Sharing] How to prevent confirm and alert boxes from showing

Hi,

I had a support case recently with a customer who is using TruClient IE 11.52. They face an issue that is reproduced on certain machines and was resolved in 12.0x. For some reason TruClient IE does not perform click on Confirm/Alert boxes causing the script to hang during replay.

I wanted to share an easy workaround - prevent the confirm/alert box from showing. I have seen this issue more than once and in all cases the workaround below didn't affect the functionality of the application under test

 

Script before the workaround:

  1. ..... script logic before relevant part
  2. Step A that triggers pop up box(es).
  3. Click OK on confirm box
  4. Click OK on alert box
  5. .... script logic after relevant part

 

Workaround

  1. Add "Evaluate JavaScript" step before the step that triggers the pop-ups with the following code in it

 

// Save original alert and confirm functions in order to restore them later

var browserAlert - window.alert;

var browserConfirm = window.confirm;

 

// Override browser alert and confrm behavior not to issue a pop-up

window.alert = function() { return true; }

window.confirm = function() { return true; }

 

2. Add "Evaluate JavaScript:" step after the step that triggers the pop-ups with the following code in it

 // Restore normal behavior of confirm and alert boxes

window.alert = browserAlert;

window.confirm = browserConfirm;

 

Script after the workaround

  1. ..... script logic before relevant part
  2. Evaluate JavaScript to prevent pop up boxes from showing
  3. Step A that triggers pop up box(es).
  4. Evaluate JavaScript to restore pop up boxes
  5. .... script logic after relevant part

 

Notice that there is no need in the Click OK steps anymore since the browser does not show them

 

Hope it helps

 Shlomi

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.