views:

153

answers:

2

I'm trying to set up a field to prepopulate with a unique set of characters, so that i can automatically generate test accounts. Because of the way the system is set up, the name field must be unique, and must not include numerical characters.

I put together this selenium code, and it works 99% of the way, but leaves extra garbage characters at the end of the good code.

javascript{stringtime=''; 
nowtime=new Date().getTime().toString(); 
for ( var i in nowtime ) 
  { stringtime+=String.fromCharCode(parseInt(nowtime[i])+65 ); }; 
'test' + stringtime + '\0'}

Result: testBCEBBJCBFBBAI + a bunch of characters that won't copy into here. They look like 4 zeros in a box.

Thanks in advance for the help.

A: 

Those characters are ones that are outside the standard ASCII that your font can't reproduce. Those numbers signify which character it is. If its 4 zeros, its that \0 char you are putting on at the end. I don't know the language, but it doesn't look like you need that.

Also your random number generator is a bit flawed. Have a look here:

http://www.mediacollege.com/internet/javascript/number/random.html

Daniel A. White
Thanks for the input, but when I remove that, I still get a long string of that character. 22 in total. It seems like selenium might be trouble with the looping?
Derek
+1  A: 

Excluding the '\0' character at the end, which shows up at a ?, and within Selenium, I think it's javascript engine is having trouble processing the for(var i in nowtime). Try it like this:

javascript{
  stringtime= '';
  nowtime=new Date().getTime().toString();
  for(var i = 0; i < nowtime.length; i++){
    stringtime += String.fromCharCode(parseInt(nowtime[i])+65);
  }
  stringtime;
}
s_hewitt
From http://www.asciitable.com/ - '\0' is a null code so that is why you are getting the weird symbols.
s_hewitt
see my comment below. Even without my null code, I still have a problem.
Derek
Updated after testing in Selenium IDE
s_hewitt
Thanks! That worked perfectly.
Derek