O2 Script/API GMail.cs
From
Using WatiN to create a GMail account
This script shows how to implement a complex workflow using O2's scripting capabilities and WatiN's web automation API.
In this case we will semi-automatically create an new GMail email address (the process cannot be fully automated due to the CAPTCHA and mobile phone verificaiton requirements)
The script workflow is:
- open a new instance of IE
- navigate to https://www.google.com/accounts/NewAccount?service=mail
- ask user to provide the desired new account name/email and password
- auto populate the following fields, checkboxes and listbox:FirstName, LastName, Email, Passwd, PasswdAgain, homepageSet, PersistentCookie, smhck, questions, IdentityAnswer
- click on the 'check availability!' button
- if required ask the user for the CAPTCHA protecting multiple 'check availability!' requests
- ask the user to resolve the main 'new account creation' CAPTCHA
- click on the Submit button
- when the next page loads, ask the used for his mobile phone number, populate the 'MobileNumber' field with the provided value and submit the form
- in the next page, ask the user to enter the mobile phone verification number, populate the 'idvGivenAnswer' field and submit the form
- to complete the process open the http://mail.google.com/mail page
video
- here is a video with the script execution
source code
var ie = "".ie(0,480,800,600); ie.open("https://www.google.com/accounts/NewAccount?service=mail"); var credential = ie.askUserForUsernameAndPassword(); var newUsername = credential.username(); var newPassword = credential.password(); ie.textField("FirstName").value("first"); ie.textField("LastName").value("last"); ie.textField("Email").value(newUsername); ie.textField("Passwd").value(newPassword); ie.textField("PasswdAgain").value(newPassword); ie.checkBox("homepageSet").uncheck(); ie.checkBox("PersistentCookie").uncheck(); ie.checkBox("smhck").uncheck(); ie.selectList("questions").select(2); ie.textField("IdentityAnswer").value("This is an answer to the question"); ie.button("check availability!").click(); ie.wait(500); // need to sleep a little bit to allow the Javascript update to happen ie.resolveCaptcha("checkavailurl", "checkavailcaptcha"); ie.button("check availability!").click(); ie.resolveCaptcha("newaccounturl", "newaccountcaptcha"); ie.button("submitbutton").click(); // next page: if (ie.textFieldExists("MobileNumber")) { var mobileNumber = ie.askUserQuestion("What is your mobile number", "O2 Question",""); ie.textField("MobileNumber").value(mobileNumber); ie.button("submitbutton").click(); //verify mobile var answerInMobile = ie.askUserQuestion("What is the verification code", "O2 Question",""); ie.textField("idvGivenAnswer").value(answerInMobile); ie.button("submitbutton").click(); // we should be in http://mail.google.com/mail/help/intro.html ie.open("http://mail.google.com/mail"); } //ie.closeInNSeconds(50); return "all done"; //O2File:WatiN_IE_ExtensionMethods.cs //O2File:WatiN_IE.cs //using SHDocVw //using WatiN.Core //O2Ref:Interop.SHDocVw.dll //O2Ref:WatiN.Core.1x.dll
