Closing unexpected HTML dialog boxes during playback

You can use the dynamic find() API to close HTML dialog boxes that are displayed unexpectedly during playback, to ensure smooth playback.

HCL OneTest™ UI provides the unexpected window handling feature to handle unexpected windows that are displayed during playback. For more information about this feature, see Configuring how to handle unexpected windows during playback.

You can also use the dynamic find() API, modified as shown in this example, to close HTML dialog boxes, both Html.Dialog or Html.HtmlDialog, that are displayed unexpectedly during playback. If you use this example during playback, it takes precedence over the unexpected window handling settings in the Configure Handling of Unexpected Windows dialog box.

public static void closeHtmlBrowserDialogs() {

	
	//Get all domains and search each domain 
	DomainTestObject domains[] = getDomains();
	for (int i = 0; i < domains.length; ++i) {
		if (domains[i].getName().equals("Html")) { // Look for the HTML web domain. Once HTML is found, get the top-level test objects.
			TestObject[] topLevelObjects = domains[i].getTopObjects();
			if (topLevelObjects != null) {
				for (int j = 0; j < topLevelObjects.length; ++j) {
					
					String className = null;
					try{
						className  = (String) topLevelObjects[j].getProperty(".class");
						
					} catch (PropertyNotFoundException ex){ // Throw an exception property not found exception
															// when the requested get property was not available
						ex.printStackTrace(); // print the detailed exception if any
					}
					
					// If Html.HtmlDialog or Html.Dialog pop-up windows are displayed during playback, both are handled. 					
					if((className != null) && (className.equalsIgnoreCase("Html.Dialog")
												||className.equalsIgnoreCase("Html.HtmlDialog")) )
							 ((TopLevelTestObject) topLevelObjects[j]).close(); // The HTML pop-up window is closed.
					
				}
			}
			
			
		}
	}
	
	unregisterAll(); // Clean up any used test objects to prevent memory-related problems.
Feedback