Shift
Shift

Reputation: 43

Interacting and Submitting HTML form with JavaScript in Swift

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.

Upvotes: 2

Views: 806

Answers (1)

kkiermasz
kkiermasz

Reputation: 463

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)

Upvotes: 1

Related Questions