我编写了一个测试用例,用于创建随机电子邮件以输入到电子邮件字段
package DDselenium.general;
import org.apache.commons.lang3.RandomStringUtils;
public class GenerateData {
public String generateRandomString(int length){
return RandomStringUtils.randomAlphabetic(length);
}
public String generateRandomNumber(int length){
return RandomStringUtils.randomNumeric(length);
}
public String generateRandomAlphaNumeric(int length){
return RandomStringUtils.randomAlphanumeric(length);
}
public String generateStringWithAllobedSplChars(int length,String allowdSplChrs){
String allowedChars="abcdefghijklmnopqrstuvwxyz" + //alphabets
"1234567890"; //numbers
return RandomStringUtils.random(length, allowedChars);
}
public String generateEmail(int length) {
String allowedChars="abcdefghijklmnopqrstuvwxyz" + //alphabets
"1234567890"; //numbers
String email="";
String temp=RandomStringUtils.random(length,allowedChars);
email=temp.substring(0,temp.length()-9)+"@test.org";
return email;
}
public String generateUrl(int length) {
String allowedChars="abcdefghijklmnopqrstuvwxyz" + //alphabets
"1234567890"; //Numbers
String url="";
String temp=RandomStringUtils.random(length,allowedChars);
url=temp.substring(0,3)+"."+temp.substring(4,temp.length()-4)+"."+temp.substring(temp.length()-3);
return url;
}
}
我生成随机电子邮件
driver.findElement(By.id("email")).sendKeys(genData.generateEmail(30));
我遇到的问题是我有一个确认电子邮件的字段,所以实际的代码是这样的
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys(genData.generateEmail(30));
driver.findElement(By.id("emailconfirm")).clear();
driver.findElement(By.id("emailconfirm")).equals("email");
问题是,我不知道如何让emailconfirm元素复制电子邮件元素中的内容。
感谢任何帮助。
答案 0 :(得分:2)
这纯粹是一个Java问题,与Selenium无关!
String email = genData.generateEmail(30);
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("emailconfirm")).clear();
driver.findElement(By.id("emailconfirm")).sendKeys(email);