Dynamic Find() API for JavaScript dialogs

You can test the JavaScript dialogs when you play back a script by using the Web UI engine. You can use the dynamic find() API to find and take action on the controls of the dynamic JavaScript dialogs such as alert, prompt, or confirm dialogs.

The following example shows how to use the dynamic find() API to search the web page to find the controls such as the Ok, Cancel, or Confirm buttons on the dynamic JavaScript dialogs that pop up when you run the test.
public class FindBased extends FindBasedHelper
{
	public void testMain(Object[] args) 
	{
		startBrowser("edge","http://civcez229.nonprod.hclpnp.com/aries-web/Samples/javascriptsamples/javascript_popupboxes.html");
		sleep(15);
		RootTestObject root = null;
		TestObject[] testObj = null;

//Alert - OK		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.INPUT.button",".id","alert"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.DialogButton",".text","OK"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);

//Confirm - OK		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.BUTTON",".id","confirm"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);
		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.DialogButton",".text","OK"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);

//Confirm - Cancel		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.BUTTON",".id","confirm"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);
		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.DialogButton",".text","Cancel"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);

//Prompt - OK		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.BUTTON",".id","prompt"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);
		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.DialogButton",".text","OK"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);

//Prompt - Cancel		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.BUTTON",".id","prompt"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);
		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.DialogButton",".text","Cancel"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);
		
//Prompt - Value - OK
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.BUTTON",".id","prompt"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);
		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.Dialog"));
		System.out.println("testObj length : " + testObj.length);
		((TopLevelTestObject) testObj[0]).inputChars("There");
		sleep(5);
		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.DialogButton",".text","OK"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);
		
//Prompt - Value - Cancel
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.BUTTON",".id","prompt"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);
		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.Dialog"));
		System.out.println("testObj length : " + testObj.length);
		((TopLevelTestObject) testObj[0]).inputChars("Harry Pottar");
		sleep(5);
		
		root = getRootTestObject();
		testObj = root.find(atDescendant(".class","Html.DialogButton",".text","Cancel"));
		System.out.println("testObj length : " + testObj.length);
		((GuiTestObject) testObj[0]).click();
		sleep(5);
		
	}
}