Find target URL in each links in a page using advanced Selenium IDE script

In this article, we will create Selenium IDE routine that will find a target URL (we will use "webfoobar.com") in each links in each Google search page results until it finds the target URL. The Selenium IDE standard set of commands can't accomplish this task, we will need additional plugin "Flow control" that provides goto, while, etc. commands.As of this writing, the latest Selenium IDE does not support "Flow control" plugin additional commands and we will need to install legacy Selenium IDE plugin (version 2.9.1.1). Another is the latest Firefox does not support the Selenium IDE plugin version 2.9.1.1 so we will install Firefox Extended Support Release (ESR 52) its older version of Firefox that supports legacy Add-Ons.

Steps:

  1. Download and install Firefox 52 ESR.

  2. Open your Firefox and go to https://addons.mozilla.org/en-GB/firefox/addon/selenium-ide/versions. Browse down until you find the version that is compatible with your Firefox 52 ESR:

    Selenium IDE previous versions download page

    Click the "Add to Firefox" button to install it.

  3. Install the Selenium IDE: Flow Control Firefox plugin.

  4. This is optional. Install sideflow (a flow control extension for Selenium IDE) by downloading the sideflow.js here. Run Selenium IDE from Firefox and open the "Options" menu and add the sideflow.js file to the "Selenium Core extensions (user-extensions.js)" field.

  5. In your Selenium IDE window, enter "https://www.google.com" in the "Base URL" field.

  6. Inside your Selenium IDE's "Table" tab, copy and paste the following codes:

          
    <tr>
    	<td>open</td>
    	<td>/search?q=pagespeed+rpm</td>
    	<td></td>
    </tr>
    <tr>
    	<td>store</td>
    	<td>css=#pnnext > span.csb.ch</td>
    	<td>click</td>
    </tr>
    <tr>
    	<td>while</td>
    	<td>storedVars['click'] == 'css=#pnnext > span.csb.ch'</td>
    	<td></td>
    </tr>
    <tr>
    	<td>storeEval</td>
    	<td>
    var anchorEl = window.document.getElementsByTagName('a');
    var found = false;
    var ourSites = [
      'webfoobar.com'
    ];
    var nonTarget = [
      'Website',
      'Cached',
      'Similar'
    ];
    for(var i = 0; i ]+)>)/ig,"");
          break;
        }
      }
      if (found) {
        break;
      }
    }
      </td>
    	<td></td>
    </tr>
    <tr>
    	<td>clickAndWait</td>
    	<td>${click}</td>
    	<td></td>
    </tr>
    <tr>
    	<td>endWhile</td>
    </tr>
          
        

    It should look like this:

    Selenium IDE advanced script example

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.