Alternative Way to Automate Web Pages: Use Key Emulation Functions

 

Sometimes you will encounter websites that make it difficult to access web page elements. The elements

may not have a Name or Value property or multiple objects in the web page have the same Name property

or the web page makes use of an assortment of different web technologies such as JavaScripts, ASP, PHP,

etc. An alternative way (sometimes easier way) to automate these elements is to use the Newbie Key

Emulation Functions:

 

Function SendKeyPress(sKey : string): boolean;
Function SendKeyPressToWindow(WndTitle, sKey : string; nDelay: integer): boolean;

Function SendString(str : string): boolean;
Function SendStringToWindow(WndTitle, str : string; nDelay: integer): boolean;
Function WaitForWindowKeyPress(sWindowTitle, sKey: string) : boolean;

Function WaitSendKeyPress(sKey: string; nDelay: integer; nTimes: integer): boolean;
 

Newbie provides these functions to allow users to automatically send strings and key commands

to the Web Browser, the same way a user would normally type the strings and key commands manually.

First example, you want to assign a string to a text field on a web page but the text field does not have

a Name property to reference it using the Fill() function. Using the Key Emulation Functions, you can send

the TAB character X number of times until the text field has the focus. Then, assign the value using

SendString() function.

 

// assume it takes 5 TABS to set focus to text field

For i := 1 to 5 do

  SendKeyPress('TAB');

SendString('Hello');

 

Second example, you can manipulate the Browser's menu commands using the Key Emulation Functions.

If you want to save the currently loaded web page, you normally would press "ALT+F" to bring up the

File menu and select "Save As..." menu option. You can automate this using the following:

 

SendKeyPress("ALT+F");

SendKeyPress("A");

Refer to the User's Manual on the list of all Key Commands.

 

 

Newbie Web Automation