在添加用户扩展时,我遇到了selenium IDE的问题。代码在html中正确地生成随机电子邮件,但是selenium似乎没有将"@mail.com“连接到生成的字符串。
在selenium中:随机字符串||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;}
发布于 2012-11-28 18:46:23
这一行可能会有错误:
var string = string+"@mail.com";我不是javascript专家,但在我看来,你又在初始化那个变量了。尝试删除此行开头的var
发布于 2012-11-29 19:29:47
生成随机电子邮件
使用我的代码生成随机电子邮件,它对我来说是正确的。
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 ||
https://stackoverflow.com/questions/13602443
复制相似问题