Share
Go down
Jens4711
Posts : 3
Join date : 2013-10-16

New to Selenium IDE

on Wed Oct 16, 2013 6:26 pm
Hi,

I have a list of URLs in a txt file (approx 2000 links).


Now I would like Selenium to visit each of the 2000 URLs after another and collect (e.g. store in a txt file) the URLs regarding the news on the page.


Since the list of URLs for the news is shown on multiple pages (only 15 at a time) I managed with this code:
open ...
clickAndWait//div[@id='W333']/div[3]/span[3]
clickAndWait//div[@id='W333']/div[3]/span[4]
clickAndWait//div[@id='W333']/div[3]/span[5]
clickAndWait//div[@id='W333']/div[3]/span[6]
clickAndWait//div[@id='W333']/div[3]/span[7]
clickAndWait//div[@id='W333']/div[3]/span[8]
clickAndWait//div[@id='W333']/div[3]/span[9]
to automatically navigate to the other pages and get the additional news-URLs shown.

What I do NOT know - and hope for your help is:
1. How do I make Selenium IDE to load one URL after the other (out of my txt file with 2000 links)
2. How do I make Selenium IDE to store all the wanted URLs of the visited pages and multipages (if more than 15) to a new txt file. (Even if just all URLs of the pages (approx 300 each time) are stored it would be all right for the moment, because I can select the right ones via EXCEL-Formulas)

I hope anyone can help me here as I do not know how to program really.

Many thanks in advance.
avatar
kashyap_guru
Active particpant
Active particpant
Posts : 24
Join date : 2013-10-16
Age : 31
Location : India

Re: New to Selenium IDE

on Wed Oct 16, 2013 7:30 pm
You need to run for or while loop with count like i=0 to i=1999. And after opening each link, you need to store that url with STORELOCATION and parameter should be link${i+1}. So it will store all opened urls like link1,link2 and so on.
Jens4711
Posts : 3
Join date : 2013-10-16

Re: New to Selenium IDE

on Thu Oct 17, 2013 3:49 am
Thanks for your answer.
But in the Selenium IDE window (that I start from my Firefox browser) I cannot find the commands you mention. The command-line has a drop-down menue and there searched for while and loop but couldn't find them. So how an where do I use these commands?

Many thanks.
avatar
kashyap_guru
Active particpant
Active particpant
Posts : 24
Join date : 2013-10-16
Age : 31
Location : India

Re: New to Selenium IDE

on Thu Oct 17, 2013 10:59 am
Sorry for incomplete answer. You need js file for FOR and WHILE loops.
Below is the code. Copy code after the '*' line to before the '*' line.

******************************************************
var gotoLabels= {};
var whileLabels = {};

// overload the original Selenium reset function
Selenium.prototype.reset = function() {
    // reset the labels
    this.initialiseLabels();
    // proceed with original reset code
    this.defaultTimeout = Selenium.DEFAULT_TIMEOUT;
    this.browserbot.selectWindow("null");
    this.browserbot.resetPopups();
}


/*
* --- Initialize Conditional Elements --- *
* Run through the script collecting line numbers of all conditional elements
* There are three a results arrays: goto labels, while pairs and forEach pairs
*
*/
Selenium.prototype.initialiseLabels = function()
{
    gotoLabels = {};
    whileLabels = { ends: {}, whiles: {} };
    var command_rows = [];
    var numCommands = testCase.commands.length;
    for (var i = 0; i < numCommands; ++i) {
        var x = testCase.commands[i];
        command_rows.push(x);
    }
    var cycles = [];
    var forEachCmds = [];
    for( var i = 0; i < command_rows.length; i++ ) {
        if (command_rows[i].type == 'command')
        switch( command_rows[i].command.toLowerCase() ) {
            case "label":
                gotoLabels[ command_rows[i].target ] = i;
                break;
            case "while":
            case "endwhile":
                cycles.push( [command_rows[i].command.toLowerCase(), i] )
                break;
            case "foreach":
            case "endforeach":
                forEachCmds.push( [command_rows[i].command.toLowerCase(), i] )
                break;
        }
    }
    var i = 0;
    while( cycles.length ) {
        if( i >= cycles.length ) {
            throw new Error( "non-matching while/endWhile found" );
        }
        switch( cycles[i][0] ) {
            case "while":
                if( ( i+1 < cycles.length ) && ( "endwhile" == cycles[i+1][0] ) ) {
                    // pair found
                    whileLabels.ends[ cycles[i+1][1] ] = cycles[i][1];
                    whileLabels.whiles[ cycles[i][1] ] = cycles[i+1][1];
                    cycles.splice( i, 2 );
                    i = 0;
                } else ++i;
                break;
            case "endwhile":
                ++i;
                break;
        }
    }

}

Selenium.prototype.continueFromRow = function( row_num )
{
    if(row_num == undefined || row_num == null || row_num < 0) {
        throw new Error( "Invalid row_num specified." );
    }
    testCase.debugContext.debugIndex = row_num;
}

// do nothing. simple label
Selenium.prototype.doLabel = function(){};

Selenium.prototype.doGotoLabel = function( label )
{
    if( undefined == gotoLabels[label] ) {
        throw new Error( "Specified label '" + label + "' is not found." );
    }
    this.continueFromRow( gotoLabels[ label ] );
};

Selenium.prototype.doGoto = Selenium.prototype.doGotoLabel;

Selenium.prototype.doGotoIf = function( condition, label )
{
    if( eval(condition) ) this.doGotoLabel( label );
}

Selenium.prototype.doWhile = function( condition )
{
    if( !eval(condition) ) {
        var last_row = testCase.debugContext.debugIndex;
        var end_while_row = whileLabels.whiles[ last_row ];
        if( undefined == end_while_row ) throw new Error( "Corresponding 'endWhile' is not found." );
        this.continueFromRow( end_while_row );
    }
}

Selenium.prototype.doEndWhile = function()
{
    var last_row = testCase.debugContext.debugIndex;
    var while_row = whileLabels.ends[ last_row ] - 1;
    if( undefined == while_row ) throw new Error( "Corresponding 'While' is not found." );
    this.continueFromRow( while_row );
}

Selenium.prototype.doPush= function(value, varName)
{
    if(!storedVars[varName]) {
        storedVars[varName] = new Array();
    }
    if(typeof storedVars[varName] !== 'object') {
        throw new Error("Cannot push value onto non-array " + varName);
    } else {
        storedVars[varName].push(value);
    }
}

// Generate random text for a variable
// Possible options:
//   length      number indicating how long to make the string (defaults to Cool
//
//   type        string indicating what type of string to create alpha, numeric
//               or alphanumeric (defaults to alphanumeric)
//
//   length|type pipe delimited option list

Selenium.prototype.doRandomString = function( options, varName ) {

    var length = 8;
    var type   = 'alphanumeric';

    var o = options.split( '|' );

    for ( var i = 0 ; i < 2 ; i ++ ) {
        if ( o[i] && o[i].match( /^\d+$/ ) )
            length = o[i];

        if ( o[i] && o[i].match( /^(?:alpha)?(?:numeric)?$/ ) )
            type = o[i];
    }

    switch( type ) {
        case 'alpha'        : storedVars[ varName ] = randomAlpha( length ); break;
        case 'numeric'      : storedVars[ varName ] = randomNumeric( length ); break;
        case 'alphanumeric' : storedVars[ varName ] = randomAlphaNumeric( length ); break;
        default             : storedVars[ varName ] = randomAlphaNumeric( length );
    };
};

function randomNumeric ( length ) {
    return generateRandomString( length, '0123456789'.split( '' ) );
}

function randomAlpha ( length ) {
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );
    return generateRandomString( length, alpha );
}

function randomAlphaNumeric ( length ) {
    var alphanumeric = '01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );
    return generateRandomString( length, alphanumeric );
}

function generateRandomString( length, chars ) {
    var string = '';
    for ( var i = 0 ; i < length ; i++ )
        string += chars[ Math.floor( Math.random() * chars.length ) ];
    return string;
}
**********************************************************

Now save this file with any name you like but save it with .js extension and save it in such directory where your not gonna move it.

Now, go to selenium. Go to Menu->Options->Options.

Select you file with field named "Selenium Core Extensions" and then click OK.

Close selenium ide once and reopen it. Search for FOR and WHILE commands.

You will find it.
Jens4711
Posts : 3
Join date : 2013-10-16

Re: New to Selenium IDE

on Sat Oct 19, 2013 3:25 am
Many thanks kashyap_guru



but sorry. This seems to be too sophisticated for me! I can find a command called "endwhile" and "endwhileandwait" in the dropdown menue now, but I don't know if they have not already been there before I did all the things you mention in your post?!?

So where is the command that starts the while loop? And what do I have to fill in into the filds Target and Value? The step-width? The start-number?

Many thanks again!
avatar
kashyap_guru
Active particpant
Active particpant
Posts : 24
Join date : 2013-10-16
Age : 31
Location : India

Re: New to Selenium IDE

on Fri Oct 25, 2013 11:58 am
If There is "endWhile" and "endWhileAndWait", then there should be "While" and "WhileAndWait" command as well.

You can use selBlocks addon of selenium to include XML file having your all desired links. Selenium will read all your data in XML file.

Then you can use fileLogging addon of selenium to export all your logs to file to be saved. It will save all your input data in test case. So you will get all your desired links saved.
gvs048
Posts : 6
Join date : 2013-03-16

Re: New to Selenium IDE

on Tue Feb 11, 2014 6:15 pm
Watch this video 

Sponsored content

Re: New to Selenium IDE

Back to top
Permissions in this forum:
You cannot reply to topics in this forum