Fill fields WebView in Java automatically

前端 未结 2 941
不知归路
不知归路 2021-02-09 18:50

So here\'s my problem. I\'m using WebView class from JavaFX in swing. The thing I want to do is that I want fields loaded in webview to be filled automatically with information

2条回答
  •  爱一瞬间的悲伤
    2021-02-09 19:28

    I fixed this with JavaFX webView Javascript engine. If anyone is intersted here's code snippet.

        String setLastName  =  "document.getElementsByName('lastName')[0].value='" + lastName + "';";
        String setName =  "document.getElementsByName('firstName')[0].value='" + name + "'";
        String setDateBirth = "document.getElementsByName('birthdate')[0].value='" + datebirth + "';";
        String setPhone = "document.getElementsByName('phone')[0].value='" + phone + "';";
        String setEmail = "document.getElementsByName('email')[0].value='" + email + "';";
        String setPassport = "document.getElementsByName('passport')[0].value='" + passport + "';";
        Button button = new Button("Fill the form");
    
        button.setOnAction(new EventHandler() {
            @Override
            public void handle(ActionEvent actionEvent) {
                webEngine.executeScript(setLastName);
                webEngine.executeScript(setName);
                webEngine.executeScript(setDateBirth);
                webEngine.executeScript(setPhone);
                webEngine.executeScript(setEmail);
                webEngine.executeScript(setPassport);
            }
        });
    

提交回复
热议问题