0% found this document useful (0 votes)
48 views4 pages

Gmail Creation Script

The document is a Java class that automates the signup process for a Gmail account using Selenium WebDriver. It generates random first names and usernames, simulates human-like typing, and navigates through the signup form fields. The script runs for 10 cycles to create multiple accounts, filling in personal information and handling various web elements accordingly.

Uploaded by

aataarambam8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views4 pages

Gmail Creation Script

The document is a Java class that automates the signup process for a Gmail account using Selenium WebDriver. It generates random first names and usernames, simulates human-like typing, and navigates through the signup form fields. The script runs for 10 cycles to create multiple accounts, filling in personal information and handling various web elements accordingly.

Uploaded by

aataarambam8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

public class InstagramSignupAutomation {

static String[] firstNames = {"Arun", "Karthik", "Venkat", "Ananya", "Divya"};


static String[] lastNames = {"Reddy", "Iyer", "Pillai", "Nair", "Menon"};
static String targetProfile = "yshsbbsua"; // Change to the profile you want to
follow

public static void main(String[] args) {


System.setProperty("webdriver.chrome.driver", "C:\\Users\\sk asif\\
Downloads\\chromedriver-win64\\chromedriver.exe");

ChromeOptions options = new ChromeOptions();


options.addArguments("--disable-blink-features=AutomationControlled");
WebDriver driver = new ChromeDriver(options);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));

for (int i = 0; i < 10; i++) { // Run 10 cycles for testing


try {
System.out.println("Cycle #" + (i + 1));

driver.get("https://accounts.google.com/signup");
String firstname = generateRandomName();
String username = generateUsername(firstname);
String mailpassword = "Test@12345";
creategmailaccount(driver, wait, firstname,username, mailpassword);
Thread.sleep(3000);

} catch (Exception e) {
e.printStackTrace();
}
}
driver.quit();
}

private static void creategmailaccount(WebDriver driver, WebDriverWait wait,


String firstname, String username, String mailpassword) {
try {
WebElement firstNameField =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("firstName")));

// Simulate human-like typing for first name


for (char c : firstname.toCharArray()) {
firstNameField.sendKeys(Character.toString(c));
Thread.sleep(200 + (int)(Math.random() * 300)); // Random delay
between keystrokes
}

// Click 'Next' to move to the date of birth and gender page


WebElement nextButton =
driver.findElement(By.xpath("//span[text()='Next']"));
nextButton.click();

// Wait for date of birth and gender fields


WebElement dayField =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("day")));
WebElement monthDropdown = driver.findElement(By.id("month"));
WebElement yearField = driver.findElement(By.id("year"));
WebElement genderDropdown = driver.findElement(By.id("gender"));
// Fill in date of birth (example: 15th August 1995)
for (char c : "15".toCharArray()) {
dayField.sendKeys(Character.toString(c));
Thread.sleep(200 + (int)(Math.random() * 300));
}
Thread.sleep(2000);
monthDropdown.click();
Thread.sleep(2000);
WebElement monthOption =
driver.findElement(By.xpath("//option[text()='August']"));
monthOption.click();
Thread.sleep(2000);
for (char c : "1995".toCharArray()) {
yearField.sendKeys(Character.toString(c));
Thread.sleep(200 + (int)(Math.random() * 300));
}

// Select gender from dropdown (example: Male)


genderDropdown.click();
WebElement genderOption =
driver.findElement(By.xpath("//option[text()='Male']"));
genderOption.click();
Thread.sleep(2000);
// Click 'Next' to move to the email selection page
nextButton = driver.findElement(By.xpath("//span[text()='Next']"));
nextButton.click();
Thread.sleep(3000);

// Locate the "Create your own Gmail address" element and click it
WebElement customGmailButton =
driver.findElement(By.xpath("//div[contains(text(),'Create your own Gmail
address')]") );
customGmailButton.click();
Thread.sleep(3000);
WebElement usernameField =
driver.findElement(By.xpath("//input[@name='Username']"));

// Simulate human-like typing for username


for (char c : username.toCharArray()) {
usernameField.sendKeys(Character.toString(c));
Thread.sleep(200 + (int)(Math.random() * 300));
}
Thread.sleep(2000);

// Click 'Next' to move to the password page


nextButton = driver.findElement(By.xpath("//span[text()='Next']"));
nextButton.click();
Thread.sleep(2000);

//
// Locate the "Password" input field and enter a value
WebElement passwordField =
driver.findElement(By.xpath("//input[@name='Passwd']"));
for (char c : mailpassword.toCharArray()) {
passwordField.sendKeys(Character.toString(c));
Thread.sleep(200 + (int)(Math.random() * 300));
}
Thread.sleep(1000);

// Locate the "Confirm Password" input field and enter a value


WebElement confirmPasswordField =
driver.findElement(By.xpath("//input[@name='PasswdAgain']"));
for (char c : mailpassword.toCharArray()) {
confirmPasswordField.sendKeys(Character.toString(c));
Thread.sleep(200 + (int)(Math.random() * 300));
}
Thread.sleep(1000);

// Click 'Next' to complete the signup


nextButton = driver.findElement(By.xpath("//span[text()='Next']"));
nextButton.click();
Thread.sleep(3000);

} catch (Exception e) {
e.printStackTrace();
}
}

public static boolean fillUsername(WebDriver driver, String username) {


WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

List<WebElement> elements = driver.findElements(By.className("uxXgMe"));


if (!elements.isEmpty()) {
WebElement createOwnOption =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("[jsname='CeL6Qc'
]")));
createOwnOption.click();
}

wait.until(ExpectedConditions.elementToBeClickable(By.name("Username")));
WebElement usernameField;

if (!driver.findElements(By.xpath("//div[contains(text(),'Create your own


Gmail address')]")).isEmpty()) {
WebElement customGmailButton =
driver.findElement(By.xpath("//div[contains(text(),'Create your own Gmail
address')]") );
customGmailButton.click();

try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

usernameField = driver.findElement(By.xpath("//input[@name='Username']"));
usernameField.clear();

for (char c : username.toCharArray()) {


usernameField.sendKeys(Character.toString(c));
try {
Thread.sleep(200 + (int)(Math.random() * 300));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

WebElement nextButton = driver.findElement(By.className("VfPpkd-LgbsSe"));


nextButton.click();

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

return true;
}

public static String generateRandomName() {


Random random = new Random();
String firstName = firstNames[random.nextInt(firstNames.length)];
String lastName = lastNames[random.nextInt(lastNames.length)];
return firstName + " " + lastName;
}

public static String generateUsername(String fullName) {


Random random = new Random();
int randomNumber = 1000 + random.nextInt(9000);
return (fullName.replace(" ", ".") + randomNumber).toLowerCase();
}

You might also like