NOTE: For those of you participating in the live Webinar, the following link will open the documentation in a new browser window.
In this two part series on writing scripts for web pages we will explore the use of the JAWS and MAGic scripting language for providing more efficient access to web page information. We will look at a variety of different scripts and functions designed to locate information on web pages. This lesson will focus on two specific exercises designed to provide practice in creating basic website related scripts.
Scripting can be used to automatically fill out information in a form. This can save users a great deal of time when there is a need to fill out repetetive pieces of information. The following web page will be used for this example Web track sample form on Surf's Up.
The purpose of this script is to automatically fill out two pieces of information in the Web Track sample form. Before writing the script it is important to examine the layout and order of the form. In our script we want JAWS to automatically enter the name and phone number and then activate the Mailing Address button. Although there are many other form fields available on the form, for the purpose of this script we will stick with just the name and phone number boxes.
The following is a list of some of the functions and scripts we will use in this exercise.
We start by creating a blank script with the name FormFiller and assigning it to the keystroke CTRL+SHIFT+F. Be sure to add an appropriate synopsis and description.
The first thing our script needs to do is move the virtual cursor to the first form field on the page. This is accomplished using the MoveToFormField function. In order to tell JAWS we want to move to the first field on the page, we pass the S_Top constant as the first parameter to the function.
Once the cursor is located on the edit field we use the TurnOnFormsMode function to activate forms mode. We can then use TypeString to type some text into the edit box.
Before moving the cursor to the next form field to enter the phone number, we must first exit out of forms mode in order to reactivate the virtual cursor. This is done by using the PerformScript statement to call the ExitFormsMode script. Depending on the speed of the computer your script is running on it may be necessary to use the Delay function to let the script pause for a couple of milliseconds after the TypeString function and before exiting forms mode. If you're unsure as to whether or not a delay is needed you can try it without a delay and see if it works. It may also be necessary to insert another delay after the ExitFormsMode script is run. This gives the computer time to perform the actions needed to exit forms mode and reactivate the virtual cursor.
We can now use the MoveToFormFieldByIndex function to move the cursor to the phone number edit box. Pass the number 2 as the parameter to MoveToFormFieldByIndex to tell JAWS to move to the second form field on the page. This is the phone number edit box. Note that it may be necessary again to call the Delay function in order to give the computer time to keep up with your script.
After activating forms mode again you can use the TypeString function to type out the phone number. You can then use several of the steps above to delay the script and then exit forms mode.
Finally, you use the MoveToFormFieldByIndex function again to jump directly to the Mailing Address button. The index of the button is 7 which you can determine by counting the number of fields on the page. For example, the first field has an index of 1, the second has an index of 2 and so on. Once the cursor is positioned on the button you can use the TypeKey function and pass the string "SPACEBAR" to have your script simulate a SPACEBAR press.
The script that we have written is only going to work if we are on the page with the Web Track sample form. If we are on any other page there could be unintended consequences or errors. We can use the GetDocumentPath function to determine if we are on the correct page before we execute any of the steps in our script. If we are not on the correct page, we can alert the user and exit the script.
You may notice that JAWS speaks extra information while the script is running. JAWS automatically speaks because the script is causing various events to fire that cause messages to be spoken. You can use the SpeechOff function to turn off speech while JAWS is moving to the form fields and then use SpeechOn to turn it back on again.
The following is the script in its entirety.
Script FormFieldEntry ();CTRL+SHIFT+F
If GetDocumentPath () != "http://www.freedomscientific.com/Training/Surfs-Up/WebTrack.htm" Then
SayFormattedMessage (OT_Message, "This script is only available on the Web Track sample form", "Not available")
return
EndIf
SpeechOff (false)
MoveToFormField (s_top)
TurnOnFormsMode ()
TypeString ("Ryan Jones")
Delay(2)
PerformScript ExitFormsMode ()
Delay (2)
MoveToFormFieldByIndex (2)
Delay(2)
TurnOnFormsMode ()
Delay(2)
TypeString ("800-444-4443")
PerformScript ExitFormsMode ()
Delay(1)
MoveToFormFieldByIndex (7)
SpeechOn ()
TypeKey ("SPACEBAR")
EndScript
The purpose of this exercise is to have JAWS automatically move the cursor to the location of a placemarker each time the page loads. This benefits the user in that there is no need to press a keystroke to move the cursor to the placemarker. We will use the Freedom Scientific home page for this exercise.
We first need to put a placemarker at the spot we want the cursor to jump to each time. On the Freedom Scientific home page, move to the level two heading called "Latest news" and add a temporary placemarker by pressing CTRL+WINDOWS+K.
In order to make JAWS move to the placemarker automatically, we need to modify the DocumentLoadedEvent. This is a default event function that fires each time a web page is loaded. A custom version of DocumentLoadedEvent is located in Internet Explorer.jss so we can simply modify this event function and add our own statements at the end.
Locate DocumentLoadedEvent and insert a blank line right before the EndFunction statement. This is where we will add our own statements so as not to interfere with the default processing of the function.
As with the previous exercise it is important to insure our statements only run on one particular page and not on every page we open. We can use the GetDocumentPath function in an If-Then statement to insure we are on the page http://www.freedomscientific.com/default.asp.
We can now use the MoveToPlaceMarkerN script and pass it the number one to tell JAWS to move to the first placemarker on the page. Because MoveToPlaceMarkerN is a script and not a function, we use the PerformScript statement to call it.
The additional code added at the bottom of DocumentLoadedEvent in Internet Explorer.jss should look like the following.
If GetDocumentPath () == "http://www.freedomscientific.com/default.asp" Then
PerformScript MoveToPlaceMarkerN (1)
EndIf
One added bonus to using a temporary placemarker verses a permanent one is that if we move the placemarker on the page, JAWS will then jump to that spot each time the page loads. This prevents you from having to modify the script if you want JAWS to automatically move to a new spot when the page loads.