-1

How to select from available usernames while creating Gmail account using Selenium when the username was chosen is already taken?

driver.get("https://accounts.google.com/SignUp?service=mail&continue=https://mail.google.com/mail/?pc=topnav-about-en");
Thread.sleep(1000);
driver.manage().window().maximize();
Thread.sleep(1000);
driver.findElement(By.id("FirstName")).sendKeys("7 Grams");
Thread.sleep(1000);
driver.findElement(By.id("LastName")).sendKeys("Cafe");
Thread.sleep(1000);
driver.findElement(By.id("GmailAddress")).sendKeys("7gcafe");
Thread.sleep(1000);

I wanted steps after this: I am looking to select the first suggested username that appears in the available usernames.

0

1 Answer 1

1

In Selenium python: first we find email input and send keys, when it's wrong we use try to find error message and except new email address with e.g. random int added. For username similar with another selector.

   email = self.driver.find_element_by_css_selector("input#GmailAddress")
   email.send_keys("kowalski")
   next_step = self.driver.find_element_by_css_selector("input#submitbutton")
   next_step.click()
   try:
       error = self.driver.find_element_by_css_selector("span.errormsg")
   except Exception:
       email2 = self.driver.find_element_by_css_selector("input#GmailAddress")
       rand = random.randint(1, 10)
       randS = str(rand)
       email2.send_keys("kowalski"+randS)

Now in gmail it is no username suggestion Now it looks like this.

5
  • Hi, thank you so much. Could you assist me in writing this in Selenium Java? I am looking to select the first available username that Gmail is suggesting when the username we chose is already taken.
    – VarzTester
    Jun 5, 2017 at 23:44
  • If you want i can rewrite this code in Java. Please try to to trigger situation with suggesting usernames and make screen of html code.
    – siutex
    Jun 7, 2017 at 12:52
  • WebElement gmailUsername = driver.findElement(By.cssSelector("input#GmailAddress")); gmailUsername.sendKeys("abcabc"); WebElement submitButton = driver.findElement(By.cssSelector("input#submitbutton")); submitButton.click(); try{ WebElement errorMessage = driver.findElement(By.cssSelector("span.errormsg")); WebElement gmailUsername2 = driver.findElement(By.cssSelector("div.username-suggestions>a:first-of-type")); gmailUsername2.click(); submitButton.click(); } catch(WebDriverException e){ e.printStackTrace(); }
    – siutex
    Jun 8, 2017 at 5:22
  • String error = driver.findElement(By.xpath(".//*[@id='errormsg_0_GmailAddress']")).getText(); if(error.equals("That username is taken. Try another.")) { List<WebElement> available = driver.findElements(By.xpath(".//*[@id='username-suggestions']/a")); System.out.println("Size "+available.size()); for(int i=1;i<=available.size();i++) { WebElement e = driver.findElement(By.xpath(".//*[@id='username-suggestions']/a["+i+"]")); e.click(); break; } }
    – VarzTester
    Jun 8, 2017 at 22:55
  • I have tried this and is working....Thank you
    – VarzTester
    Jun 8, 2017 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.