I am attempting to load a web page with the JavaFX WebView control. The specific page is: https://bitfinex.com/login. Then, once the load worker's state has been set to SUCCEEDED, I use the w3c Document API to execute Javascript on the loaded webpage. Specifically I want to auto-fill the email login input and then focus the password input. For some reason, for this particular page, nothing happens (the page just loads and the two text inputs remain blank). I have used this exact procedure on a couple other login pages, and it has worked flawlessly (one example being: https://www.coinbase.com/signin). This leaves me very confused. My thoughts have ranged from is the Bitfinex site somehow "blocking" interaction? Also, why is the load worker state set to SUCCEEDED twice (you will see I use an if statement to guard against this by checking if the two elements are still null, which should not be necessary to my understanding and wasn't necessary for the other pages, but I don't know if this is related to the problem at hand? Is this some really obscure, strange bug that will be very difficult to replicate/drill-down? Anyways..I hope this will be cleared up.
The code:
package test;
import javafx.application.Application;
import javafx.concurrent.Worker;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import org.w3c.dom.Document;
import org.w3c.dom.html.HTMLInputElement;
public class MainApp extends Application
{
public static void main(String[] args) throws Exception
{
launch(args);
}
public void start(Stage stage) throws Exception
{
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
webEngine.load("https://www.bitfinex.com/login");
webView.setPrefSize(610, 610);
webEngine.getLoadWorker().stateProperty().addListener((observableValue, oldState, newState) ->
{
if (newState == Worker.State.SUCCEEDED)
{
Document document = webEngine.getDocument();
if (document.getElementById("login") == null || document.getElementById("auth-password") == null)
{
return;
}
((HTMLInputElement) document.getElementById("login")).setValue("john_appleseed@gmail.com");
((HTMLInputElement) document.getElementById("auth-password")).focus();
}
});
stage.setScene(new Scene(webView));
stage.show();
}
}