Python API

JavaAccessBridge

exception RPA.JavaAccessBridge.ElementNotFound

Bases: ValueError

No matching elements were found.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class RPA.JavaAccessBridge.JavaAccessBridge(ignore_callbacks: bool = False, access_bridge_path: str = None)

Bases: object

Java application UI automation library using Java Access Bridge technology.

Library is at the beta level at the moment so feedback is highly appreciated.

The library utilizes java-access-bridge-wrapper package to interact with Java UI. Currently only the 64-bit Windows OS is supported.

Steps to enable

  1. Enable the Java Access Bridge in Windows

  2. Set environment variable RC_JAVA_ACCESS_BRIDGE_DLL as an absolute path to WindowsAccessBridge-64.dll. It is also possible to give DLL location as library initialization parameter access_bridge_path.

C:\path\to\java\bin\jabswitch -enable
set RC_JAVA_ACCESS_BRIDGE_DLL=C:\path\to\Java\bin\WindowsAccessBridge-64.dll
*** Settings ***
Library   RPA.JavaAccessBridge   access_bridge_path=C:\path\to\Java\bin\WindowsAccessBridge-64.dll

About Java wrapper callbacks and actions

There might be a compability issue with callbacks and actions on target Java application. Possible reasons:

  • target application is executed with 32-bit Java

  • target application does not support callbacks and/or actions

Workaround for this situation is to initialize JavaAccessBridge library with parameter ignore_callbacks=True. Then application’s element information is still accessible and any actions on those elements can be performed with RPA.Desktop library.

Note. There are still keywords, for example. Call Element Action, which will cause error if used in this situation. To be fixed in future release.

*** Settings ***
Library   RPA.JavaAccessBridge   ignore_callbacks=True

Locating elements

To automate actions on the Java application, the robot needs locations to various elements using a feature called locators. Locator describes properties of an element.

At the moment library contains basic level support for locators.

The common locator types are name and role.

To identify element with more than one property and can be used, for example:

role:push button and name:Clear

To address element within parent element > can be used, for example:

name:Find Purchase Orders > name:NumberField

Some keywords accept element as an parameter in place of locator.

Interacting with elements

By default application elements are interacted with Actions supported by the element. Most common example is click action supported by an button element.

But because application and technology support for the actions might be limited, it is also possible to opt for interaction elements by their coordinates by giving keyword parameter action=False if parameter is available.

Inspecting elements

Inspecting Java application elements depends on what kind of Java UI framework the application has been built with.

The Accessibility Insights for Windows can show element properties if application framework supports Windows UI Automation (UIA), see more at using Accessibility Insights.

The Google’s Access Bridge Explorer can also be used for inspecting Java application elements.

Examples

robotframework

*** Settings ***
Library   RPA.JavaAccessBridge
Library   Process

*** Tasks ***
Write text into Swing application
    Start Process    java -jar BasicSwing.jar
    ...              shell=${TRUE}
    ...              cwd=${CURDIR}
    Select Window    Chat Frame
    Type Text    role:text
    ...          text for the textarea
    Type Text    role:text
    ...          text for the input field
    ...          index=1
    ...          clear=${TRUE}
    Click Element    role:push button and name:Send

Python

from RPA.JavaAccessBridge import JavaAccessBridge
import subprocess

jab = JavaAccessBridge()

subprocess.Popen(
    ["java", "-jar", "BasicSwing.jar"],
    shell=True,
    cwd=".",
    close_fds=True
)
jab.select_window("Chat Frame")
jab.type_text(
    "role:text",
    "text for the textarea",
    enter=True
)
jab.type_text(
    "role:text",
    "text for the input field",
    index=1,
    clear=True
)
jab.click_element("role:push button and name:Send")
ROBOT_AUTO_KEYWORDS = False
ROBOT_LIBRARY_DOC_FORMAT = 'REST'
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
application_refresh()

Refresh application element tree

Might be required action after application element structure changes after window refresh.

call_element_action(locator: str, action: str)

Call element action

Parameters
  • locator – target element

  • action – name of the element action to call

click_element(locator: Union[JABWrapper.context_tree.ContextNode, str], index: int = 0, action: bool = True, timeout: int = 10)

Click element

Parameters
  • target – element to click

  • index – target element index if multiple are returned

  • action – call click action on element (default), or use coordinates

  • timeout – timeout in seconds to find element

click_push_button(button_name: str)

Click element of role push button

Parameters

button_name – name of the button to click

get_element_actions(locator: str)

Get list of possible element actions

Parameters

locator – target element

get_element_text(locator: Union[JABWrapper.context_tree.ContextNode, str], index: int = 0)

Get element text

Parameters
  • locator – target element

  • index – target element index if multiple are returned

get_elements(locator: str)

Get matching elements

Parameters

locator – elements to get

get_version_info()

Get Java Access Bridge version information

highlight_element(locator: Union[JABWrapper.context_tree.ContextNode, str], index: int = 0)

Highlight an element

Parameters
  • locator – element to highlight

  • index – target element index if multiple are returned

press_keys(*keys)

Press multiple keys down simultaneously

See Desktop library documentation for supported keys

Parameters

keys – keys to press

print_element_tree(filename: str = None)

Print current element into log and possibly into a file

Parameters

filename – filepath to save element tree

select_menu(menu: str, menuitem: str)

Select menu by clicking menu elements

Parameters
  • menu – name of the menu

  • menuitem – name of the menu item

select_window(title: str, bring_foreground: bool = True, timeout: int = 30)

Selects Java application window as target for the automation

Parameters
  • title – application window title

  • bring_foreground – if application is brought to foreground or not

  • timeout – selection timeout

set_mouse_position(element: JABWrapper.context_tree.ContextNode)

Set mouse position to element center

Parameters

element – target element

shutdown_jab()

Call Java Access Bridge process shutdown

toggle_drop_down(locator: str, index: int = 0)

Toggle dropdown action on element

Parameters
  • locator – element locator

  • index – target element index if multiple are returned

type_text(locator: str, text: str, index: int = 0, clear: bool = False, enter: bool = False)

Type text into coordinates defined by locator

Parameters
  • locator – target element

  • text – text to write

  • index – target element if multiple are returned

  • clear – should element be cleared before typing

  • enter – should enter key be pressed after typing

wait_until_element_is_focused(locator: Union[JABWrapper.context_tree.ContextNode, str], index: int = 0, timeout: float = 0.5)

Wait until element is focused

Parameters
  • locator – target element

  • index – target element index if multiple are returned

  • timeout – timeout in seconds to wait, default 0.5 seconds

wait_until_element_text_contains(locator: Union[JABWrapper.context_tree.ContextNode, str], text: str, index: int = 0, timeout: float = 0.5)

Wait until element text contains expected text

Parameters
  • locator – target element

  • text – element text should contain this

  • index – target element index if multiple are returned

  • timeout – timeout in seconds to wait, default 0.5 seconds

wait_until_element_text_equals(locator: Union[JABWrapper.context_tree.ContextNode, str], text: str, index: int = 0, timeout: float = 0.5)

Wait until element text equals expected text

Parameters
  • locator – target element

  • text – element text should match this

  • index – target element index if multiple are returned

  • timeout – timeout in seconds to wait, default 0.5 seconds