Python API
SAP
- class RPA.SAP.SAP(*args, **kwargs)
This library wraps the upstream [https://frankvanderkuur.github.io/SapGuiLibrary.html|SapGuiLibrary].
The SapGuiLibrary is a library that enables users to create tests for the Sap Gui application
The library uses the Sap Scripting Engine, therefore Scripting must be enabled in Sap in order for this library to work.
= Opening a connection / Before running tests =
First of all, you have to make sure the Sap Logon Pad is started. You can automate this process by using the AutoIT library or the Process Library.
After the Sap Login Pad is started, you can connect to the Sap Session using the keyword connect to session.
If you have a successful connection you can use Open Connection to open a new connection from the Sap Logon Pad or Connect To Existing Connection to connect to a connection that is already open.
= Locating or specifying elements =
You need to specify elements starting from the window ID, for example, wnd[0]/tbar[1]/btn[8]. In some cases the SAP ID contains backslashes. Make sure you escape these backslashes by adding another backslash in front of it.
= Screenshots (on error) =
The SapGUILibrary offers an option for automatic screenshots on error. Default this option is enabled, use keyword disable screenshots on error to skip the screenshot functionality. Alternatively, this option can be set at import.
- ROBOT_LIBRARY_SCOPE = 'GLOBAL'
- click_element(element_id)
Performs a single click on a given element. Used only for buttons, tabs and menu items.
In case you want to change a value of an element like checkboxes of selecting an option in dropdown lists, use select checkbox or select from list by label instead.
- click_toolbar_button(table_id, button_id)
Clicks a button of a toolbar within a GridView ‘table_id’ which is contained within a shell object. Use the Scripting tracker recorder to find the ‘button_id’ of the button to click
- connect_to_existing_connection(connection_name)
Connects to an open connection. If the connection matches the given connection_name, the session is connected to this connection.
- connect_to_session(explicit_wait=0)
Connects to an open session SAP.
See Opening a connection / Before running tests for details about requirements before connecting to a session.
Optionally set explicit wait can be used to set the explicit wait time.
Examples: | Keyword | Attributes | | connect to session | | | connect to session | 3 | | connect to session | explicit_wait=500ms |
- disable_screenshots_on_error()
Disables automatic screenshots on error.
- doubleclick_element(element_id, item_id, column_id)
Performs a double-click on a given element. Used only for shell objects.
- element_should_be_present(element_id, message=None)
Checks whether an element is present on the screen.
- element_value_should_be(element_id, expected_value, message=None)
Checks whether the element value is the same as the expected value. The possible expected values depend on the type of element (see usage).
Usage: | Element type | possible values | | textfield | text | | label | text | | checkbox | checked / unchecked | | radiobutton | checked / unchecked | | combobox | text of the option to be expected |
- element_value_should_contain(element_id, expected_value, message=None)
Checks whether the element value contains the expected value. The possible expected values depend on the type of element (see usage).
Usage: | Element type | possible values | | textfield | text | | label | text | | combobox | text of the option to be expected |
- enable_screenshots_on_error()
Enables automatic screenshots on error.
- focus_and_click(element_id: str, wait_time: Optional[float] = None)
Set focus into the element and click it.
Note. The default library wait time can be adjusted using Set Explicit Wait keyword. Library’s explicit_wait will be used if wait_time parameter is not set.
- Parameters
element_id – locator for the element
wait_time – the wait time after the action
- focus_and_input_text(element_id: str, text: str, wait_time: Optional[float] = None)
Set focus into the element and input text into it.
Note. The default library wait time can be adjusted using Set Explicit Wait keyword. Library’s explicit_wait will be used if wait_time parameter is not set.
- Parameters
element_id – locator for the element
text – text to be inputted
wait_time – the wait time after the action
- generic_click_element(element_id, click_type='press')
Performs a single click on a given element.
Differs from Click Element keyword so that element type is ignored, instead click_type (either press or select) is performed on the element if possible.
In case you want to change a value of an element like checkboxes of selecting an option in dropdown lists, use select checkbox or select from list by label instead.
- Parameters
element_id – locator for the element
click_type – either
press
(default) orselect
- generic_input_password(element_id, password)
Inserts the given password into the text field identified by locator.
This keyword does NOT depend on the type of the element. Will set password to the element’s ‘text’ attribute if possible.
The password is not recorded in the log.
- Parameters
element_id – locator for the element
password – password to be inputted
- generic_input_text(element_id, text)
Inserts the given text into the text field identified by locator. Use keyword input password to insert a password in a text field.
This keyword does NOT depend on the type of the element. Will set text to the element’s ‘text’ attribute if possible.
- Parameters
element_id – locator for the element
text – text to be inputted
- get_cell_value(table_id, row_num, col_id)
Returns the cell value for the specified cell.
- Parameters
table_id – locator for the table element
row_num – table row number
col_id – table cell id
- Returns
text in the specified cell
- get_element_location(element_id)
Returns the Sap element location for the given element.
- get_element_type(element_id)
Returns the Sap element type for the given element.
- get_element_type_of_object(element)
Returns the Sap element type for the given element.
- Parameters
element – SAP element
- Returns
type of the SAP element
- get_row_count(table_id)
Returns the number of rows found in the specified table.
- get_scroll_position(element_id)
Returns the scroll position of the scrollbar of an element ‘element_id’ that is contained within a shell object.
- get_statusbar_type(window: Optional[str] = 'wnd[0]') str
Retrieves the messageType in the statusbar the given window.
Takes screenshot on error.
- Parameters
window – locator for the statusbar, default ‘wnd[0]’
- Returns
messageType of the /sbar element or empty string
- get_value(element_id)
Gets the value of the given element. The possible return values depend on the type of element (see Return values).
Return values: | Element type | Return values | | textfield | text | | label | text | | checkbox | checked / unchecked | | radiobutton | checked / unchecked | | combobox | text of the selected option | | guibutton | text | | guititlebar | text | | guistatusbar | text | | guitab | text |
- get_window_title(locator)
Retrieves the window title of the given window.
- input_password(element_id, password)
Inserts the given password into the text field identified by locator. The password is not recorded in the log.
- input_text(element_id, text)
Inserts the given text into the text field identified by locator. Use keyword input password to insert a password in a text field.
- maximize_window(window=0)
Maximizes the SapGui window.
- open_connection(connection_name)
Opens a connection to the given connection name. Be sure to provide the full connection name, including the bracket part.
- press_f1(element_id: str)
Calls the PressF1 function on the passed element id. The element can be a textfield or a GridView inside a shell.
- Parameters
element_id – id of the SAP element
- press_f4(element_id: str)
Calls the PressF4 function on the passed element id. The element can be a textfield or a GridView inside a shell.
- Parameters
element_id – id of the SAP element
- run_transaction(transaction)
Runs a Sap transaction. An error is given when an unknown transaction is specified.
- scroll(element_id, position)
Scrolls the scrollbar of an element ‘element_id’ that is contained within a shell object. ‘Position’ is the number of rows to scroll.
- select_checkbox(element_id)
Selects checkbox identified by locator. Does nothing if the checkbox is already selected.
Selects an item from the context menu by clicking a button or right-clicking in the node context menu.
- select_from_list_by_label(element_id, value)
Selects the specified option from the selection list.
- select_node(tree_id, node_id, expand=False)
Selects a node of a TableTreeControl ‘tree_id’ which is contained within a shell object.
Use the Scripting tracker recorder to find the ‘node_id’ of the node. Expand can be set to True to expand the node. If the node cannot be expanded, no error is given.
- select_node_link(tree_id, link_id1, link_id2)
Selects a link of a TableTreeControl ‘tree_id’ which is contained within a shell object.
Use the Scripting tracker recorder to find the ‘link_id1’ and ‘link_id2’ of the link to select.
- select_radio_button(element_id)
Sets radio button to the specified value.
- select_table_column(table_id, column_id)
Selects an entire column of a GridView ‘table_id’ which is contained within a shell object.
Use the Scripting tracker recorder to find the ‘column_id’ of the column to select.
- select_table_row(table_id, row_num)
Selects an entire row of a table. This can either be a TableControl or a GridView ‘table_id’ which is contained within a shell object. The row is an index to select the row, starting from 0.
- send_vkey(vkey_id, window=0)
Sends a SAP virtual key combination to the window, not into an element. If you want to send a value to a text field, use input text instead.
To send a vkey, you can either use te VKey ID or the Key combination.
Sap Virtual Keys (on Windows) | VKey ID | Key combination | VKey ID | Key combination | VKey ID | Key combination | | 0 | Enter | 26 | Ctrl + F2 | 72 | Ctrl + A | | 1 | F1 | 27 | Ctrl + F3 | 73 | Ctrl + D | | 2 | F2 | 28 | Ctrl + F4 | 74 | Ctrl + N | | 3 | F3 | 29 | Ctrl + F5 | 75 | Ctrl + O | | 4 | F4 | 30 | Ctrl + F6 | 76 | Shift + Del | | 5 | F5 | 31 | Ctrl + F7 | 77 | Ctrl + Ins | | 6 | F6 | 32 | Ctrl + F8 | 78 | Shift + Ins | | 7 | F7 | 33 | Ctrl + F9 | 79 | Alt + Backspace | | 8 | F8 | 34 | Ctrl + F10 | 80 | Ctrl + Page Up | | 9 | F9 | 35 | Ctrl + F11 | 81 | Page Up | | 10 | F10 | 36 | Ctrl + F12 | 82 | Page Down | | 11 | F11 or Ctrl + S | 37 | Ctrl + Shift + F1 | 83 | Ctrl + Page Down | | 12 | F12 or ESC | 38 | Ctrl + Shift + F2 | 84 | Ctrl + G | | 14 | Shift + F2 | 39 | Ctrl + Shift + F3 | 85 | Ctrl + R | | 15 | Shift + F3 | 40 | Ctrl + Shift + F4 | 86 | Ctrl + P | | 16 | Shift + F4 | 41 | Ctrl + Shift + F5 | 87 | Ctrl + B | | 17 | Shift + F5 | 42 | Ctrl + Shift + F6 | 88 | Ctrl + K | | 18 | Shift + F6 | 43 | Ctrl + Shift + F7 | 89 | Ctrl + T | | 19 | Shift + F7 | 44 | Ctrl + Shift + F8 | 90 | Ctrl + Y | | 20 | Shift + F8 | 45 | Ctrl + Shift + F9 | 91 | Ctrl + X | | 21 | Shift + F9 | 46 | Ctrl + Shift + F10 | 92 | Ctrl + C | | 22 | Ctrl + Shift + 0 | 47 | Ctrl + Shift + F11 | 93 | Ctrl + V | | 23 | Shift + F11 | 48 | Ctrl + Shift + F12 | 94 | Shift + F10 | | 24 | Shift + F12 | 70 | Ctrl + E | 97 | Ctrl + # | | 25 | Ctrl + F1 | 71 | Ctrl + F | | |
Examples: | Keyword | Attributes | | | send_vkey | 8 | | | send_vkey | Ctrl + Shift + F1 | | | send_vkey | Ctrl + F7 | window=1 |
- set_cell_value(table_id, row_num, col_id, text)
Sets the cell value for the specified cell of a GridView ‘table_id’ which is contained within a shell object.
Use the Scripting tracker recorder to find the ‘col_id’ of the cell to set.
- set_explicit_wait(speed)
Sets the delay time that is waited after each SapGui keyword.
The value can be given as a number that is considered to be seconds or as a human-readable string like 1 second or 700 ms.
This functionality is designed to be used for demonstration and debugging purposes. It is not advised to use this keyword to wait for an element to appear or function to finish.
Possible time formats:
miliseconds | milliseconds, millisecond, millis, ms |seconds | seconds, second, secs, sec, s |minutes | minutes, minute, mins, min, m |Example:
Keyword | Attributes |Set explicit wait | 1 |Set explicit wait | 3 seconds |Set explicit wait | 500 ms |
- set_focus(element_id)
Sets the focus to the given element.
- take_screenshot(screenshot_name='sap-screenshot')
Takes a screenshot, only if ‘screenshots on error’ has been enabled, either at import of with keyword enable screenshots on error.
This keyword uses Robots’ internal Screenshot library.
- unselect_checkbox(element_id)
Removes selection of checkbox identified by locator. Does nothing if the checkbox is not selected.