ConnectHTML

Purpose With connectHTML you can read values from an HTML page that you have displayed with the  View command. You can also change values and perform various actions, such as clicking on a link. Both your own HTML pages and any internet or intranet pages can be used. The display via  View can be integrated into the SAP screen or can be a separate “floating” window. For further details please see our documentation “Special Topics”,  “Automating internet pages”.
Example connectHTML click=“button_Continue”

The button “Continue” is clicked in the HTML page that is currently displayed via  View.

Format  When there is only one HTML page currently opened via View - which is the standard case – you can use
  • connectHTML options

without specifying  window=“…”. All options and HTML variables html[...] then refer to this page. In cases where there are several active View windows, you can specify the desired window explicitly:

  • connectHTML options window=“&V[viewwindow]“

Here you use the window number returned by a ”View …. returnwindow=viewwindow” statement. All options and HTML variables then refer to this window.

You have to use a connectHTML command only when you either use special options (see below), or you need to specify the window. Otherwise you can immediately use the HTML variables:

  • Set html[name] “value”          // Sets a value into the HTML page
  • “… &html[name] …”           // reads a value from the HTML page        
  • if html[name]                   // queries the existence of an HTML element        

 

Options 
 

window=

Explicit specification of the window number returned by a  View …. returnwindow= statement.

In this context, please observe the following: When you display an HTML page within the SAP screen (not as a separate window), and you need to refer to this page with  connectHTML or need to use HTML variables for this page in the same GuiXT script, you have to work with returnwindow= in the  View statement. Only when you use this option is the view window opened synchronously. Without  returnwindow= you can refer to the HTML page only when the SAP screen is displayed, e.g. in an InputScript started with a button on this screen, or when the same screen is displayed again without changing the View statement.
This is not necessary in the case of HTML Views that you display in a separate window with 
View …. -floating, since these windows are always displayed synchronously, i.e. they are created before the next script statement is executed.

click= You name the HTML element (e.g. a button, an image or a link) that is to be clicked. Example:

connectHTML click=“image_search.jpg”

geturl= This returns the current URL of the HTML page.  You can use it if you want to be sure that the user has not left the page. Example:

connectHTML geturl=“url”
if not Q[ok] or not V[url=http:// ... /basket.asp]
   Return “E: Please display the ‘shopping basket’ first” -statusline
endif

seturl= Displays the HTML page with the given URL
gettitle= Returns the page title.
settitle= Sets a new page title. Since  View does not display the page title, this is for internal use only where you want to read the page title later on.
 

listelements=

All HTML elements of the current page are shown in the given text variable (long text). This is useful during script development, since you can then copy&paste the HTML element names from the text window. Example:

// GuiXT Script
Pushbutton (toolbar)
“Read HTML elements” process=“get_html_elements.txt”
Textbox
(10,0) (40,120) name=“elm”

// InputScript “get_html_elements.txt”
connectHTML
listelements=“elm”

-shownames To be used during script development: The name of each HTML element is displayed as “tooltip” in the HTML page, provided the mouse points to this element for a few seconds.
searchbrowserwindow= Returns an open browser window (Internet Explorer only), or 0 if not found.  With

if Q[ok]

endif

you can query whether a browser window has been found.  This window can then be used in all connecthtml statements in the same way as a View window.

index= In conjunction with searchbrowserwindow=. You specify a number i (i=1,2,3,..) for the browser window to be searched.
Using the HTML elements The  HTML variables can be used in the same way as the usual script variables V[...]. Notation is html[...]. You can use it in following contexts:
  • Set html[name] “value”          // Sets a value into the HTML page
  • “… &html[name] …”           // reads a value from the HTML page        
  • if html[name]                   // queries the existence of an HTML element        

After a new value is set, GuiXT automatically invokes the “on change” routine of the HTML page for this element. In the case of drop down fields (Select element) it is necessary in some cases to perform a click on this element after changing it, using  click=. Otherwise some of the internal processing in the HTML page might be missing.

When you automate the user interaction for an HTML page, the means provided by connectHTML are sufficient in most cases (setting values and clicking on links, buttons or images). However, in other cases, where special JavaScript or VBScript functions are used or there are special plugins in the page, the automation of the user interaction can be beyond the connectHTML capabilities.

How to name the HTML elements During development we suggest you use the listelements= and -shownames features to display the HTML element names.

GuiXT builds the name of an element in the following way: The name always starts with the element type  (image_, button_, checkbox_, …). Next,  the internal id or name of the element, or user text (like a button text). All “space” characters are replaced with underline. If duplicate names arise, GuiXT adds a suffix .2, .3,… . Examples:

html[image_help.jpg]
html[link_Search]
html[link_Search.2]
html[select_Country]
html[text_Search_Filter]

HTML Tables  Tables are quite common in HTML pages. They can be nested. GuiXT allows us to address each table cell. For the names, GuiXT uses the following notation: cell_i.j.k is  cell number  k of row j in table i.

For example,

html[cell_1.4.5]

denotes a cell within the first table of the page, namely the cell in row 4, column 5 (starting with 1).

For nested tables,  the name starts with the name of the cell that contains the table, followed by ‘~’  and the normal cell coordinates within the nested table. Example:

html[cell_3_1_7~1_2_2~2.2.4]

This is the following cell: Start with the third outer table of the page. Choose the cell in row 1, column 7. There is at least one nested table in this cell. Take the first one, and then the cell in row 2, column 2 of this first nested table. In this cell, there are at least 2 more nested tables (nesting level 2). Take the second one, go to row 2 and column 4, and you have reached cell cell_3_1_7~1_2_2~2.2.4.

Row count for each table

For each table GuiXT allocates an HTML variable  “…_rows” that contains the number of rows for this table. For example,

“&html[table_1_rows]“

denotes the number of rows of the first table. For nested table, the same rules as described above apply. Example:

“&html[table_3_1_7~1_rows]“

This is the number of rows of the first nested table contained in cell row 1 column 7 of the third table on the page.

Instead of using the row count, it is often more practical to query the existence of a certain cell. Example:

// row index
Set V[i] 1
  

label
begin

// no further row?
if not html[
cell_1.&V[i].1]
  goto
end
endif

… process table row

Set V[i] &V[i] + 1
goto
begin

label
end

Checkbox and radiobutton The values of a checkbox or radiobutton are represented by  0 and 1.  When you set a radiobutton all other radiobuttons in the same group are automatically reset. Example:


Set
html[radio_English] 1

Load time of HTML pages After some actions, e.g. clicking a button, a new HTML page needs to be loaded, which may take some time. Each

connectHTML  

command first waits until the page is fully loaded before performing the required action. After waiting 2 minutes,  connectHTML returns to script processing. With

if not Q[ok]
  Return
“….”
endif

after a  connectHTML you can query whether the action has been successful.

ConnectHTML