Issue
How can I generate random emails using Selenium with Java?
I was looking here in StackOverflow but I haven't found the answer to this.
I have tried with this, but it didn't help.
public class registerClass{
public static void main(String[] args) {
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = " ";
driver.get(baseUrl);
driver.manage().window().maximize();
driver.findElement(By.id("cboxClose")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.id("login")).click();
driver.findElement(By.xpath("/html/body/div[2]/div[1]/div/div[1]/div[2]/a[1]")).click();
driver.findElement(By.id("register.firstName")).sendKeys("Karla");
driver.findElement(By.id("register.paternalLastName")).sendKeys("Perez");
driver.findElement(By.id("register.maternalLastName")).sendKeys("castro");
driver.findElement(By.id("register.email")).sendKeys("[email protected]");
//driver.close();
}
}
Solution
You need random string generator. This answer I stole from here.
protected String getSaltString() {
String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder salt = new StringBuilder();
Random rnd = new Random();
while (salt.length() < 10) { // length of the random string.
int index = (int) (rnd.nextFloat() * SALTCHARS.length());
salt.append(SALTCHARS.charAt(index));
}
String saltStr = salt.toString();
return saltStr;
}
Call it as getSaltString()+"@gmail.com"
in you code
Answered By - a_a
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.