Question

I'm very new to developing Safari Extensions and I don't know any java, css or html.

I've been searching round the web for a way to interact with a website using javascript injection. Specifically, I wish to fill out two forms; a username and a password and then press the 'login' button.

I've learned that I need to use something like document.getElementById() and .click and .value, but I really don't know how to connect the dots.

Any help is much appreciated!

Kind regards, Tokke

Was it helpful?

Solution

I will assume that when you say two forms, username and password you mean two text inputs, and then submit the form.

What you should do, is:

  1. Select each text input and change its value attribute.
  2. Submit the form

Could be done with the following code, assuming that your form has an id="my-form", your username input has id="username" and your password input has id="password".

document.getElementById("username").value = "myusername"; // Select and fill username input
document.getElementById("password").value = "mypassword"; // Select and fill password input
document.getElementById("my-form").submit();              // Submit the form
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top