2
I need to access a web page, through the component WebView
.
1- I can load the page.
2- I can intercept the button event.
I can’t insert/ inject var name = prompt("Introduza o numero:");
Note: The page is only available via intranet - I cannot 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 most I can get is the return when it is falso
Any help? Is there another way?