Ui4j - WebKit

Web Automation for Java

License

License

GroupId

GroupId

io.webfolder
ArtifactId

ArtifactId

ui4j-webkit
Last Version

Last Version

4.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Ui4j - WebKit
Web Automation for Java
Project URL

Project URL

https://github.com/ui4j/ui4j
Source Code Management

Source Code Management

https://github.com/ui4j/ui4j.git

Download ui4j-webkit

How to add to project

<!-- https://jarcasting.com/artifacts/io.webfolder/ui4j-webkit/ -->
<dependency>
    <groupId>io.webfolder</groupId>
    <artifactId>ui4j-webkit</artifactId>
    <version>4.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.webfolder/ui4j-webkit/
implementation 'io.webfolder:ui4j-webkit:4.0.0'
// https://jarcasting.com/artifacts/io.webfolder/ui4j-webkit/
implementation ("io.webfolder:ui4j-webkit:4.0.0")
'io.webfolder:ui4j-webkit:jar:4.0.0'
<dependency org="io.webfolder" name="ui4j-webkit" rev="4.0.0">
  <artifact name="ui4j-webkit" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.webfolder', module='ui4j-webkit', version='4.0.0')
)
libraryDependencies += "io.webfolder" % "ui4j-webkit" % "4.0.0"
[io.webfolder/ui4j-webkit "4.0.0"]

Dependencies

provided (7)

Group / Artifact Type Version
org.openjfx : javafx-base jar 11
org.openjfx : javafx-graphics jar 11
org.openjfx : javafx-web jar 11
org.openjfx : javafx-controls jar 11
org.slf4j : slf4j-api jar 1.7.25
org.slf4j : slf4j-simple jar 1.7.25
xerces : xercesImpl jar 2.11.0

test (4)

Group / Artifact Type Version
org.testfx : openjfx-monocle jar 8u76-b04
junit : junit jar 4.12
com.eclipsesource.minimal-json : minimal-json jar 0.9.2
com.nanohttpd : nanohttpd jar 2.1.1

Project Modules

There are no modules declared in this project.

Ui4j

License FOSSA Status

Ui4j is a web-automation library for Java. It is a thin wrapper library around the JavaFx WebKit Engine, and can be used for automating the use of web pages and for testing web pages.

cdp4j (Automation for Chrome & Chromium)

Use cdp4j Java library if you need to automate Chrome or Chromium based browsers.

Supported Java Versions

Oracle & OpenJDK Java 8 and 11.

Both the JRE and the JDK are suitable for use with this library.

Licensing

Ui4j is licensed as MIT software.

Stability

This library is suitable for use in production systems.

Integration with Maven

To use the official release of ui4j, please use the following snippet in your pom.xml file.

Add the following to your POM's tag:

<dependency>
    <groupId>io.webfolder</groupId>
    <artifactId>ui4j-webkit</artifactId>
    <version>4.0.0</version>
</dependency>

Download

ui4j-webkit-4.0.0.jar - 387 KB

ui4j-webkit-4.0.0-sources.jar - 196 KB

Supported Platforms

Ui4j has been tested under Windows 10 but should work on any platform where a Java 8 or Java 11 is available.

Headless Mode

Ui4j can be run in "headless" mode using Monocle.

  1. Add maven dependency of the latest openjfx-monocle.
  2. Add -Dui4j.headless Java system parameter from command line or with using api System.setProperty("ui4j.headless", "true");

Logging

Both simple logger for java (SLF4J) and Java utility logger (JUL) is supported. If slf4j is available on classpath io.webfolder.ui4j.api.util.LoggerFactory use slf4j else java utility logger is used.

CSS Selector Engine

Ui4j use W3C selector engine which is default selector engine of WebKit. Alternatively Sizzle selector engine might be used. Sizzle is the css selector engine of JQuery and it supports extra selectors like :has(div), :text, contains(text) etc. Check the Sizzle.java for using sizzle with Ui4j.

Usage Examples

Here is a very basic sample program that uses Ui4j to display a web page with a "hello, world!" message. See the ui4j-sample project for more sample code snippets.

// get the instance of the webkit
BrowserEngine browser = BrowserFactory.getWebKit();
// navigate to blank page
Page page = browser.navigate("about:blank");
// show the browser page
page.show();
// append html header to the document body
page.getDocument().getBody().append("<h1>Hello, World!</h1>");

Here is another sampe code that list all front page news from Hacker News.

try (Page page = getWebKit().navigate("https://news.ycombinator.com")) {
    page
        .getDocument()
        .queryAll(".title a")
        .forEach(e -> {
            System.out.println(e.getText());
        });
}

Building Ui4j

mvn package

FAQ

How can i set the user agent string?

See UserAgent.java sample.

How can i execute javascript?

See JavaScriptExecution.java sample.

How can i handle browser login, prompt or confirmation dialog?

See DialogTest.java for custom handlers or use default handlers from Dialogs.java.

What is the easiest way clear all input elements?

Use clear method of the Form class.

FOSSA Status

Versions

Version
4.0.0
3.1.0
3.0.0