I'm currently creating a synthetic monitoring script, using JavaScript and the Selenium driver. However the website login consists of a random selected password character authentication.
For example the login would ask for:
3rd character of your password:[input]
5th character of your password:[input]
7th character of your password:[input]
The requested characters change each time.
I need to return the randomly generated password characters and use them as variables to allow me to automatically select whatever the login authentication requests from my password.
So far I have this in my script, however it's not working:
var password_chars = element.getText();
var char1 = parseInt(password_chars[1].match(/<div>(\d+)/)[1] -1);
var char2 = parseInt(password_chars[2].match(/<div>(\d+)/)[1] -1);
var char3 = parseInt(password_chars[3].match(/<div>(\d+)/)[1] -1);
Unfortunately I cannot include any specifics, website etc, due to private information.
So eventually I got this to work, and here's how I did it:
1.) First return the element that contains the requested password characters and split that string, in my example I had to split on a new line.
2.) Create an array to contain the split string.
3.) Parse each character request into an int. This is to remove the (th) or (nd). For example 2nd->2
4.) Now -1 from each of the ints (arrays start at 0)
5.) Apply the ints to the password array to receive the correct chars.
6.) Make the script send the correct chars as keys.
Included code below:
$browser.findElement($driver.By.className('answer')).getText()
.then(function(reqpwdchars) //7
{
console.log(reqpwdchars);
var psplit = [];
psplit = reqpwdchars.split("\n")
var char1 = psplit[0]
var int_c1= parseInt(char1)
int_c1=int_c1-1
var char2 = psplit[1]
var int_c2= parseInt(char2)
int_c2=int_c2-1;
var char3 = psplit[2]
var int_c3= parseInt(char3)
int_c3=int_c3-1
var password_array = ['e','x','a','m','p','l','e'];
var pc1 = password_array[int_c1];
var pc2 = password_array[int_c2];
var pc3 = password_array[int_c3]
$browser.findElement($driver.By.id('char1-ID')).sendKeys(pc1)
.then(function() //8
{
$browser.findElement($driver.By.id('char2-ID')).sendKeys(pc2)
.then(function() //9
{
$browser.findElement($driver.By.id('char3-ID')).sendKeys(pc3)
.then(function() //10
{
I'd like to thank John Kl for the password array idea.