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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Nagendra Kuppala
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
();
}



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c45b8747-25de-4b9c-bddc-1ce6c189833c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.