Find element by iterating through all the available TargetValues in a Queue using DeQueue

9 views
Skip to first unread message

Nagendra Kuppala

unread,
Jun 14, 2018, 2:55:52 PM6/14/18
to Selenium Users
Hello,

Need quick help on queue and DeQueue in JS.

I'm trying to pass the working Target Element to a doCommand() function which executes the step with Command, CommandTarget and Value.


var targetValue = "";
function passTarget(cmd){
    let targetStr
= getTarget(cmd);     //Example targetStr = id=btn_basic_example; link=Start Practising; css=#btn_basic_example; xpath=//a[contains(text(),'Start Practising')]; xpath=//div[@id='home']/p[2]/a; xpath=//p[2]/a
    let commandTargetStr
= targetStr.split(";");      
    let q
= new Queue();
   
for(var i =0; i<commandTargetStr.length; i++){
        q
.add(commandTargetStr[i]);
   
}    
   
// If the Target queue has only one value, return the TargetValue to doCommand to execute.
   
if (commandTargetStr.length === 1) {
        targetValue
= commandTargetStr;
        ctri_log
.info("targetValue :" + targetValue);
       
return;
   
}
   
    q
.data = q.data.reverse();
    ctri_log
.info(q.data);    // Output Queue: id=btn_basic_example,link=Start Practising,css=#btn_basic_example,xpath=//a[contains(text(),'Start Practising')],xpath=//div[@id='home']/p[2]/a,xpath=//p[2]/a
   
   
// pass first element from the queue to selectValidTarget().
   
// poll()-Removes and returns the head of the queue. Returns null if queue is empty.
   
// Lets say Top:
   
targetValue = q.poll();   // Not Working , [error] TypeError: q.poll is not a function  
}


function selectValidTarget(targetValue) {
   
try {


            ctri_log
.info("targetValue: " + targetValue);
            ctri_log
.info(targetValue +" value =  " + $(targetValue.split('=')[1]));
            ctri_log
.info(targetValue +" length =  " + $(targetValue.split('=')[1]).length);
           
           
// Check if element is present or not in a web page. If present pass Target element to doCommand ();
           
if(targetValue.startsWith('xpath')){
             
if($x(targetValue.split('=')[1]).length == 1 ){
                   
break;
             
}else if($(targetValue.split('=')[1]).length == 1 ){
                   
break;
               
}else if{ q.poll().isNotEmpty()){
                        GOTO
Top: ;
             
}else{
                   
Fail; // Pass First Target element to doCommand ();
           
}        
   
} catch (e) {
        console
.error(e);
   
}
}




function doCommand() {
    let commands
= getRecordsArray();
    let commandName
= getCommandName(commands[currentPlayingCommandIndex]);
    passTarget
(commands[currentPlayingCommandIndex]); //getCommandTarget(commands[currentPlayingCommandIndex]);
    let commandTarget
= targetValue;
    let commandValue
= getCommandValue(commands[currentPlayingCommandIndex]);
   
    execute
();
}




I basically looking for something like this:

TOP:
Let x = deque[q.data];

find
(){
         
if ( found){
                   
exit; // Check if element is present or not in a web page. If present pass Target element to doCommand ();
         
}else if(x Not Empty){   // if Queue not empty re-iterate
                   GOTO TOP
: ;
         
}else{         // if Queue empty.
                   
Fail; // Pass First Target element to doCommand ();
         
}

function doCommand() {
    let commands
= getRecordsArray();
    let commandName
= getCommandName(commands[currentPlayingCommandIndex]);
    passTarget
(commands[currentPlayingCommandIndex]); //getCommandTarget(commands[currentPlayingCommandIndex]);
    let commandTarget
= targetValue;
    let commandValue
= getCommandValue(commands[currentPlayingCommandIndex]);
   
    execute
();
}



Reply all
Reply to author
Forward
0 new messages