This is the site: https://www.parking-servis.co.rs/eng/edpk
On it, there is the form with a text field and a button. This is the source code from the page:
<div class="edpk-form">
<form>
<input type="hidden" name="_token" value="IvpmhoYWOFx4s5LPLznzg9NY2vnccX0yebxXt2Oi"> <div class="form-wrap">
<div class="input-wrap">
<input type="text" name="fine" :class="{'field-error': error}" v-model="vars.plate" :placeholder="lang.enter" required />
</div>
<div class="submit-wrap">
<button class="button blue" type="submit" @click.prevent="findTicket()">{{ lang.search }}</button>
</div>
</div>
<div :id="'pks_eZUuuzPYbGXz6nWn_wrap'" style="display:none;">
<input type="text" v-model="vars.pks_MbGfCEQWq6mwwcDm" name="pks_tFMmGu7d5GRyedr1" value="" id="pks_mxhG2rVavA6kdgbG">
<input type="text" v-model="vars.eyJpdiI6IjVYZFBwT1VQVXlOcit5Wncvd1E5TXc9PSIsInZhbHVlIjoibGQzbHY0YmJ2bjVCTUFHaDVMb0NyQT09IiwibWFjIjoiYzU5MmYxZjVjZTVkZGE1ZDA4ZmJlZjk2N2ExNGM4MWE2ZWI3ZjA5MjZiNTA0ZGQ3NzdiYzU3MGFkMGU0ZTc5OCJ9" name="pks_valid">
</div>
</form>
</div>
I'm using this code to fill in the form and press the button, but it doesn't work.
WebView webView = findViewById(R.id.webview_id);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
webView.loadUrl("javascript:(function() { " +
"document.getElementsByName('fine')[0].value = 'ABC123XY';" +
"document.forms[0].submit();" +
"})()");
It fills the form but the page keeps reloading and nothing happens. I also tried using the code below, the button is pressed correctly, but it looks like the form isn't filled, and the response I get is an error for not filling the form.
webView.loadUrl("javascript:document.querySelector('.input-wrap input[name=\"fine\"]').value = 'ABC1234XY';");
webView.loadUrl("javascript:document.querySelector('.button.blue[type=submit]').click();");
I'm an android developer, but I'm not that skilled in web development, so any help would be appreciated :)