hasan
hasan

Reputation: 315

Selenium IDE testing all links

I'm trying to use Selenium IDE to test a web app. On one page, there are several links which trigger modal windows. I'd like to test ALL the links on the page to ensure that ALL cause modals to pop up.

Each link has a class "modal" so I thought I could just change the target value in IDE css=a.modal but that finds only the first link.

I've found a few solutions but they use Selenium RC with Java/Python and those can't be directly translated to the IDE.

I understand the IDE is not as powerful but I'm setting this up for a non-programmer to use and up till now, it's been really simple for them.

Upvotes: 5

Views: 9271

Answers (3)

hasan
hasan

Reputation: 315

i had to read up a lot and i want to thank @ohaal and @aleh for their inputs. i used their suggested links as well as some more external reading to reach the solution like so:

<tr>
<td>open</td>
<td>/logout</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Forum</td>
<td></td>
</tr>
<tr>
<td>storeXpathCount</td>
<td>//p[3]/span/a[contains(@class, 'modal')]</td>
<td>users</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>i</td>
</tr>
<tr>
<td>while</td>
<td>storedVars.i&lt;=storedVars.users</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//descendant::a[contains(@class, 'modal')][${i}]</td>
<td></td>
</tr>
<tr>
<td>waitForText</td>
<td>css=h2</td>
<td>You are not logged in</td>
</tr>
<tr>
<td>click</td>
<td>css=#cross_button &gt; a &gt; img</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>javascript{storedVars.i++}</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>

i'm not selecting any one answer as all of them contributed to the final solution.

Upvotes: 5

Aleh Douhi
Aleh Douhi

Reputation: 1988

Try this (you have to download this extension):

<tr>
    <td>storeCssCount</td>
    <td>css=a.modal</td>
    <td>links</td>
</tr>
<tr>
    <td>store</td>
    <td>0</td>
    <td>i</td>
</tr>
<tr>
    <td>label</td>
    <td>l1</td>
    <td></td>
</tr>
<tr>
    <td>getEval</td>
    <td>storedVars.i++</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>//descendant::a[contains(@class, 'modal')][${i}]</td>
    <td></td>
</tr>
<tr>
    <td>gotoIf</td>
    <td>--storedVars.links</td>
    <td>l1</td>
</tr>

Insert your assertions and probably pop-ups closings before last command (gotoIf).

Upvotes: 1

ohaal
ohaal

Reputation: 5268

Use a while loop, and this XPath expression as a locator: //a[contains(@class, 'modal')]

//a[contains(@class, 'modal')][1], //a[contains(@class, 'modal')][2] and so on should point to the links you're after.

See this link for more information on how to do while loops in Selenium IDE if you are unfamiliar with it.

Upvotes: 1

Related Questions