views:

30

answers:

3

Basically we have link using span

$('#desc').click() {
//do somehting
}

<span id="desc"> This is Link </span>

And this <span> is made to look like link with style.

now, In selenium i have code which clicks link.

But, due to some javascript, which gets loaded at page load, It takes time for making those link clickable.

So click fails, but selenium does not report that. (I mean it won't it just clicked on element.)

How do i make sure that onclick event was bound before clicking on tht link in selenium ?

A: 

In your question, $('desc').click() { } does nothing, you have to do something like

<span id="myid" class="myclass"> This is Link </span>

$('span#myid').click(function() { ... });
      //or 
$('#myid').click(function() { .... });
      // or
$('.myclass').click(function() { ..... });

please refer to .selectors()

Ninja Dude
yeh...forgot to mention # in sample code. But issue is still there. So when i say its not clickable, does that mean style is not applied or something ?
Jigar Shah
+1  A: 

The problem would seem to be that the link looks clickable before it can be clicked (or, at least, before clicking it does something useful). So I'd recommend having a class for all the spans you want to look like links:

<span class="link_span">...</span>

and have the style to make them look like links:

link_like {
text-decoration: underline;
/* whatever else */
}

Then apply that class to the link_spans once the window is loaded, which comes a little while after $(document).ready()

$(window).load(
    function() {
        $('.link_span').each(
            function(){
                $(this).addClass('link_like');
            }
        );
    }
);

The point of this is that the spans won't look clickable until they can be clicked to produce an action.

Obviously the simplest solution would be to use real hyper-links, but I assume you've discounted that as a possibility already.

David Thomas
Hey David...we are doing exactly same thing. class is there with span to make it look clickable. But there some script which is running while page is loaded. Like it might be scanning all links or something (its jqModaldnr.js :)) So it looks clickable so waitForElementPresent and verifying its class passes. But link is not yet clickable as tht js script is still running.
Jigar Shah
A: 

waitFor... family perhaps suit your need.

For example, if you are sure an element presents after your java script is loaded, use: waitForElementPresent(locator)

Ding-Yi Chen