2

Trying to submit an HTML form / clicking a button from this web page: https://www.vegvesen.no/kjoretoy/Eie+og+vedlikeholde/skilt/personlig-bilskilt/sok-om-personlig-bilskilt

I've tried to use both .submit() and .click() with no success

webView.evaluateJavaScript("document.getElementById('personlig-kjennemerke').click();", completionHandler: nil)

So what I try to do is to fill in the text field with "REGNR" I then try to click the orange button to submit the form and access the information I am looking for.

I am able to fill in the textfield by using:

   webView.evaluateJavaScript("document.getElementById('tegnkombinasjon').val    ue='\(plateNumber)'") { (value, error) in

        }

Picture of the button I want to press and the text field I try to fill in

But since I'm not able to click the button programmatically I've tried to actually click it in a subview. The page then tells me I have to fill in the text field first even though I have programmatically.

So not only am I unable to click the button, but I'm also wondering how I can make the web page understand that the text field actually already contains text.

1 Answer 1

1

Try this:

webView.evaluateJavaScript("document.getElementsByName(\"sjekkreg\")[0].elements[2].click()")

Why by name? Because that form doesn't have an id.

Also I see your form has custom function to send that form:

pkCtrl.submit(mineFelt,sjekkreg)
Sign up to request clarification or add additional context in comments.

7 Comments

Excuse me. I've forgot getElementsByName returns an array. Now try above code.
@Shift Ok, try my function now. This is terrible hard coding, but this form is too.
Yes that worked great! Only had to change to \"sjekkreg\" as it was from your previous suggestion. Do you have any idea how I can let the web page know that I actually added text to the field? Because I literally have to manually click the text field and add or remove one character for it to understand the rest is there.
@Shift do you mean UITextField or input in html form?
The input field above the orange button which you have helped me out with. It seems to have a "required" statement or something that checks if the user interacted with the input? I'm new to HTML so I really appreciate your help on this.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.