Discussion Forum

Welcome to the Discussion Forum, we encourage you to REGISTER on our forum and participate in the debate.For more details Click here

Online Advertising

Viewers now you can promote Your Websites/Blogs/Products by using our online advertising program.Using this feature you can place your Ads in my blog and can attract the people logging over here.To place your ads, just sign in my Guest Book and leave your details over there.

Monday, August 3, 2009

Script Modelling and capturing the ViewState

After a script is recorded, it must be edited to capture the ViewState value dynamically. The ViewState value may be found in many pages but should only be captured just before a request that needs to use it. This is performed by simply “Addressing a DOM element” which is explained in detail by the Modeller help. How that process relates to ViewState is described here, in summary only.

After recording the script, no changes should be made to the URLs. The Yellow colored arrow icon in the tool-bar of the Script Modeller will populate the Query Pane with content of the server’s response for the selected URL. The “HTML Tree” tab in the query pane displays a tree representation of the Document Object Model (DOM).
Right click on the HTML Node and choose “Search”. In the textbox that appears, enter “VIEWSTATE” (without the quotes) and hit [Return]. Then right click on the VIEWSTATE value:

From the shortcut menu that appears, select “Address” and assign a variable name, for example “TEMP_VS”.

This will automatically insert the necessary code into the script:
LOAD RESPONSE_INFO BODY ON 1 &
INTO TEMP_VS &
,WITH "HTML(0)/BODY(1)/DIV(0)/FORM(0)/INPUT(0):ATTRIBUTE:value(2);

Unfortunately, after capturing the ViewState, simply substituting the string with the new variable in the next request will result in an HTTP 500 error when played back. There is a little more to using the captured ViewState than this, hence the “TEMP” in the chosen variable-name, “TEMP_VS”.

Using the Viewstate
The format of the ViewState is issued to the browser in literal characters. There are numerous encoded values in the ViewState, each delimited by “+”. The server, however, expects to receive the ViewState back with special characters replaced with their ASCII equivalent. The only special character that is observed to be dynamic in the ViewState string is the delimiter “+”, represented in a post body or URL query string as “%2B”.

Thus, before the captured ViewState can be successfully used, each of these “+” symbols that are interspersed in the string must be substituted with “%2B”. This can be reformatted by passing the value obtained by the “LOAD RESPONSE_INFO” command to a subroutine held in an “Include” file.

This subroutine must use the SCL commands “~LOCATE” to find the position of the next “+”:

SET Len = ~LOCATE("+", TEMP_VS)

It is the text prior to that position that is of interest. Using “~EXTRACT”, that section of the ViewState can be copied to another variable, appending “%2B”:
SET VS = VS+~EXTRACT(0,Len,TEMP_VS)+"%2B"

That portion and the “+” is then removed from the temporary ViewState variable:
SET OFFSET = Len+1
SET TEMP_VS = ~EXTRACT(OFFSET,5120,TEMP_VS)

This must all be repeated until the temporary ViewState variable is empty. It is occasionally necessary to substitute trailing “=” symbols.
The VSTATE variable can then be used in the original script, instead of the ViewState string originally recorded:
,BODY"__VIEWSTATE="+VS+"%3D%3D&hdnIncomingURL=username
Free advertising


Lowes Coupon
How to Blog

Free Advertising