All entries for Friday 06 March 2009

March 06, 2009

Automating web workflow in Adobe AIR

This entry was created using an AIR based browser.

Yes, it's possible. I wrote a simple AIR app that signs me in to Warwick Blogs by loading the login page into an AIR app, populating the login form fields, and submitting. It's also possible to call javascript methods in the page. Here's the code:

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1024" height="768">

<mx:Script>
	<![CDATA[
 
			import mx.controls.Alert;
	
			private var domWindow:Object;
			private var blnAlertThrown:Boolean = false;
			private var load:int = 0;
						
	        private function initDomWindow(event:Event):void {
			if(load == 0)
			{
			load++;
	        domWindow = event.currentTarget.domWindow;
        	getElementFromHTML("userName").value = "myusername";
        	getElementFromHTML("password").value = "mypassword";
        	domWindow.document.forms[0].submit();
			}
			else
			{
				load++;
			}        	
	        }

	        private function getElementFromHTML(elementName:String):Object {
				var arrayContainingAllFoundElements:Object = domWindow.document.getElementsByName(elementName);
				return arrayContainingAllFoundElements[0];	
	        }
 	
	]]>
</mx:Script>

<mx:HTML id="htmlTranslate" x="10" y="84" location="http://blogs.warwick.ac.uk/blogbuilder/admin/create/plainEntry.spr?blog=094d4021fb4dbd6d00fb4de01b490001&amp;newPermissions=Anyone&amp;newCommentPermissions=Anyone" complete="initDomWindow(event)"/>
	
</mx:WindowedApplication>