I’ve wrote a simular script, so you might try this.
Make sure to click the checkbox labeled “Enable access for assistive devices” in the Universal Access System Preference pane to enable GUI scripting.
The delay times are individual, depending on how fast your Mac is, and how fast your internet connection is. Go figure what’s the best delay time for your script on your mac…
tell application "Safari"
make new document
set URL of document 1 to "https://login.yahoo.com/config/login_verify2?&.src=ym"
tell application "System Events"
tell process "Safari"