Skip to content

gaozhao1989/pyjab

Repository files navigation

pyjab

Python implementation for Java application UI automation with Java Access Bridge.

The pyjab package enables run UI automation(selenium like) through with Java UI application. Package will invoke Java Access Bridge API to get information form Java application. And this package is only support for Windows. Sources code referenced from NVDA.

The pyjab package is available on PyPI which means installation should be as simple as:

$ pip install pyjab

There's actually a multitude of ways to install Python packages (e.g. the per user site-packages directory, virtual environments or just installing system wide) and I have no intention of getting into that discussion here, so if this intimidates you then read up on your options before returning to these instructions.

Access Bridge Explorer is a Windows application that allows exploring, as well as interacting with, the Accessibility tree of any Java applications that uses the Java Access Bridge to expose their accessibility features, for example Android Studio and IntelliJ.

JRE, JDK or JAB standalone package is required. Need setup environment variable JAVA_HOME or JAB_HOME before usage.

Here's an example of how easy it is to get started:

from pyjab.jabdriver import JABDriver

# Create a JABDriver object.
jabdriver = JABDriver("java app window title")

# Find a JABElement by element name
login_btn = jabdriver.find_element_by_name("Login")

# Click a JABElement
login_btn.click()

# Some other examples.
jabdriver.find_element_by_xpath("//push button[@name=contains('OK')]")
jabdriver.wait_until_element_exist(by=By.NAME, value="Dashboard")
login_btn.get_screenshot_as_file("./screenshot.png")

You may also use a context manager approach to kill the Java Window after the JABDriver is cleared:

from pyjab.jabdriver import JABDriver

# Create a JABDriver object.
with JABDriver("java app window title") as jabdriver:

    # Find a JABElement by element name
    login_btn = jabdriver.find_element_by_name("Login")

    # Click a JABElement
    login_btn.click()

You can also open the Java window process by specifying the file path which will launch the Java WebStart process for the given file :

from pyjab.jabdriver import JABDriver

# Create a JABDriver object.
with JABDriver(title="java app window title", file_path="C:\\jnlps\\test.jnlp") as jabdriver:

    # Find a JABElement by element name
    login_btn = jabdriver.find_element_by_name("Login")

    # Click a JABElement
    login_btn.click()

The latest version of pyjab is available on PyPI and GitHub. For bug reports please create an issue on GitHub. If you have questions, suggestions, etc. feel free to send me an e-mail at [email protected].

This software is licensed under the GPLv2 license.

© 2021 Gary Gao.