Writing a script to automate Username and password fields

Hi there!
I am a noob! I was wondering if there was a way to write a script to automate the entry of general settings in the web interface of the ag300 modem router. I have, a few times, restored factory settings on my router and have wanted to write a script to automate the settings process. Is there a way to do it?
Help!
Cheers
Nash