I need to access a webpage through the WebView
component.
1- I can load the page.
2- I can intercept the button event.
I can not insert / inject var name = prompt("Introduza o numero:");
Note: The page is only available via intranet - I can not share the link.
HTML button:
<input class="SUBMIT" onclick="return collect_info();"
onmouseout="this.className='SUBMIT';" onmouseover="this.className='SUBMITOVER';"
alt="Enviar Pedido" name="3" value="Falta de mat. no YYYY" type="SUBMIT">
JavaScript Function:
function collect_info(){
var name = prompt("Introduza o numero:"); // <---- Problema aqui - Não consigo inserir este valor
// Expressao regular - apenas decimais
var regexp = /^\d\d?$/;
if (!regexp.test(name))
{
alert("Campo númerico de 2 digitos. Confirme por favor.");
return false;
}
if (name != '' && name != null)
{
var elem = document.createElement("input");
elem.type = "hidden";
elem.name = "id_c";
elem.id = "id_c";
elem.value = name;
document.forms["alarmes"].appendChild(elem);
}
else
return false;
var name = prompt("Introduza o numero:");
// Expressao regular - apenas decimais
//if (name.length < 10)
// {
// alert("Numero demasiado curto. Confirme por favor.");
// return false;
// }
if (name != '' && name != null)
{
var elem = document.createElement("input");
elem.type = "hidden";
elem.name = "id_p";
elem.id = "id_p";
elem.value = name;
document.forms["alarmes"].appendChild(elem);
return true;
}
else
return false;
}
Java code:
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.web.*;
import javafx.stage.*;
public class WebViewWithPromptHandler extends Application {
public static void main(String[] args) { launch(args); }
@Override
public void start(final Stage primaryStage) {
WebView webView = new WebView();
String url = "--->> Link <<---";
webView.getEngine().load(url);
webView.getEngine().setJavaScriptEnabled(true);
webView.getEngine().setOnAlert(event -> {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setHeaderText("Message from the web page");
alert.setContentText(event.getData());
alert.showAndWait();
});
final Scene scene = new Scene(webView);
primaryStage.setScene(scene);
primaryStage.show();
}
}
The maximum I can receive is the return of when it is falso
Any help? Is there another way?