添加用户扩展时,我遇到了selenium IDE的问题。代码在html中正确生成随机电子邮件,但selenium似乎没有将“@ mail.com”连接到生成的字符串
在硒中: randomString || 8 |邮件||的varName
我正在使用的代码在这里:http://seleniumide.blogspot.com/2010/12/random-number-generator.html
这就是我添加的内容:
function generateRandomMail( length, chars ) {
var string = '';
for ( var i = 0 ; i < length ; i++ )
string += chars[ Math.floor( Math.random() * chars.length ) ];
string = string+"@mail.com";
return string;
}
答案 0 :(得分:0)
这一行可能会出错:
var string = string+"@mail.com";
我不是javascript专家,但在我看来,你正在再次初始化该变量。尝试删除此行开头的var
答案 1 :(得分:0)
生成随机电子邮件
使用我的代码生成随机电子邮件,它对我来说正常。
Selenium.prototype.doTypeRandomEmail = function(locator) {
/**
* Sets the value of an input field to a random email id,
* as though you typed it in.
*
* @param locator an <a href="#locators">element locator</a>
*/
// All locator-strategies are automatically handled by "findElement"
var element = this.page().findElement(locator);
/* The following block generates a random email string */
var allowedChars = "abcdefghiklmnopqrstuvwxyz";
var stringLength = 8;
var randomstring = '';
for (var i=0; i<stringLength; i++) {
var rnum = Math.floor(Math.random() * allowedChars.length);
randomstring += allowedChars.substring(rnum,rnum+1);
}
// Append a domain name
randomstring += "@somedomain.com"
// Replace the element text with the new text
this.browserbot.replaceText(element, randomstring);
};
typeRandomEmail || id = wmd-input ||