Azher
Azher

Reputation: 493

After generating a random email address, I want to be able to use that same generated email address again

Problem: I am filling out an application form where it asks for an email address and to then confirm it in another text field (confirm email address).

I am using webdriverJS to write my code. I am generating the email address randomly as seen below:

var chars = 'abcdefghijklmnopqrstuvwxyz'
  return $browser.findElement($driver.By.id("brokers_register_main_broker_username")).sendKeys(chars[Math.floor(Math.random()*26)] + Math.random().toString(36).substring(2,11) + '@random.com');

The problem I am facing is that I do not know how to capture the email address that has been randomly generated and insert it in the following (confirm email address) text field.

If anyone has any idea on how to get round this problem, I would be very grateful as I have spent hours trying to figure this one out without much luck. Any assistance or a nod in the right direction would be very much appreciated. Thank you.

Upvotes: 0

Views: 1848

Answers (1)

Jayesh Doolani
Jayesh Doolani

Reputation: 1233

It's very simple. You just need to save the randomly generated email address in a variable and then reuse it again & again whenever you want. All you have to do is:

var randomEmail= chars[Math.floor(Math.random()*26)] 
                  + Math.random().toString(36).substring(2,11) 
                  + '@random.com';
return $browser.findElement($driver.By.id("brokers_register_main_broker_username"))
               .sendKeys(randomEmail);

Upvotes: 2

Related Questions