Selenium IDE testing all links - testing

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.

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<=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 > a > 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.

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.

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).

Related

Selenium goBack and wait

I have this selenium test (a part of it).
<tbody>
<tr>
<td>open</td>
<td></td>
<td>localhost:8091</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Rest objects</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Show')])[3]</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>xpath=(//div[not(div)][1])</td>
<td>ID: 2</td>
</tr>
<tr>
<td>goBack</td>
<td></td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Show')])[5]</td>
<td></td>
</tr>
<tr>
<td>goBack</td>
<td></td>
<td></td>
</tr>
</tbody>.
I use Selenium IDE in Firefox. When I run it slowly (toggle speed), it works well. However, when I try to run it faster, I get error at the step <td>clickAndWait</td> after <td>goBack</td>. The log says,
Element xpath=(//a[contains(text(),'Show')])[5] not found.
My questions, how to go back and wait until the page is loaded before I perform other actions.
You have to use waitForPageToLoad command adter click on element till the page loaded and then perform other actions
Use Below code
<tr>
<td>click</td>
<td>xpath=(//a[contains(text(),'Show')])[5]</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>10000</td>
<td></td>
</tr>
Thanks (#Trimantra Software Solution).
waitForPageToLoad this is what I needed.
From documentation:
waitForPageToLoad(timeout)
Arguments:
timeout - a timeout in milliseconds, after which this command will return with an error
Waits for a new page to load.
This is my solution, I used waitForPageToLoad after goBack.
<tbody>
<tr>
<td>open</td>
<td></td>
<td>localhost:8091</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Rest objects</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Show')])[3]</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>xpath=(//div[not(div)][1])</td>
<td>ID: 2</td>
</tr>
<tr>
<td>goBack</td>
<td></td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>800</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Show')])[5]</td>
<td></td>
</tr>
<tr>
<td>goBack</td>
<td></td>
<td></td>
</tr>
</tbody>
I see a goBackAndWait() variant of this command. That might work for you.
Typically I'd advise using a waitFor to ensure the page is back to where you want. Simplest that may work is waitForTitle if possible.
waitForElementPresent & waitForText also good ones to look at.

error Element id not found on Selenium IDE

I've been recorded a test case using Selenium IDE and I've encountered an error Element id=XXX not found. Tried using clickAndWait and still nothing happens. Scenario is that I'm on Page 1 and clicked on view then Page 2 appears. Need to check on actions on Page 2. When tried refresh it only refresh Page 1 instead of Page 2.
<tr>
<td>open</td>
<td>/index.php/admin/lead/myLeads</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=search_company_name</td>
<td>J02217 GMBH Test 1</td>
</tr>
<tr>
<td>click</td>
<td>css=span.glyphicon.glyphicon-search</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.fa.fa-info-circle</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.glyphicon.glyphicon-remove</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>id=btn-add-file</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=btn-add-file</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Close</td>
<td></td>
Add two things to your script. At the beginning
<tr>
<td>setTimeout</td>
<td>60000</td>
<td>Wait 60 seconds for the page</td>
</tr>
And after the click that launches page two
<tr>
<td>waitForPageToLoad</td>
<td>60000</td>
<td>Wait up to one minute</td>
</tr>
Welcome to Selenium testing. You should try to outgrow IDE as quickly as possible. IDE is training wheels. Move to WebDriver as soon as can. There are plenty of tutorials available.

Selenium IDE wont click on dynamic id

I'm having trouble getting a link clicked on Selenium IDE.
The id is picked from the itteration in a while loop but i can't get the ID echo'ed in somehow.
This is my code:
<tr>
<td>open</td>
<td>/list</td>
<td></td>
</tr>
<tr>
<td>storeAllLinks</td>
<td>linkArray</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>0</td>
<td>index</td>
</tr>
<tr>
<td>while</td>
<td>index < 10;</td><!-- should be array length but that wont word eighter, problem for later -->
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=${index}</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>index++;</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>1000</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
Anny clues on whats going wrong would be great help.
Thank you in advance!
You can locate link by its text. Use of Xpath and link text might help you.
Or please share part of HTML.

Selenium IDE getting id from url parameter?

I am struggling with getting the id from a url in selenium ide please could you assist me Thanks. When I echo the store location it removes the equals? PLease see the comments for the output below. Thanks for any help given.
When I run the ide tests I run it through webdriver and on internet explorer but i dont think this should make much difference.
<tr>
// gets http//website.co.uk/index.php?main_detail_id=123456789123456
<td>storeLocation</td>
<td>loc</td>
<td></td>
</tr>
<tr>
//prints http//website.co.uk/index.php?main_detail_id123456789123456
<td>echo</td>
<td>${loc}</td>
<td></td>
</tr>
<tr>
//no errors have also tried split '?'
<td>storeEval</td>
<td>"${loc}".split('=')[2]</td>
<td>mainid</td>
</tr>
<tr>
//prints nothing.
<td>echo</td>
<td>${mainid}</td>
<td></td>
</tr>
Below is code with help of that you can get ID from URL
<tr>
<td>store</td>
<td>http//website.co.uk/index.php?main_detail_id=123456789123456</td>
<td>test</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>delimiter</td>
</tr>
<tr>
<td>store</td>
<td>javascript{storedVars['test'].split('=')[storedVars['delimiter']]}</td>
<td>vv</td>
</tr>
<tr>
<td>echo</td>
<td>${vv}</td>
<td></td>
</tr>

Closing pop up frames with Selenium IDE

I am using Selenium IDE for some tests. But hardly stuck with one action - i need to close a download pop up window in FF.
Common way to perform this would be using selectWindow command, BUT - my pop up - it's actually a frame, so it does not have an ID and other useful parameters for IDE.
All my attempts to close this pop up lead to closing main window.
I tried something like this, but did not work either:
<tr>
<td>click</td>
<td>css=#fpm > img</td>
<td></td>
</tr>
<tr>
<td>waitForFrameToLoad</td>
<td>http://www.somesite.com/lg/c.do?proj=1111&aid=1111&rnd=0.132456</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>5000</td>
<td></td>
</tr>
<tr>
<td>close</td>
<td></td>
<td></td>
</tr>
<tr>
Is anybody faced this problem in the past? I know, that JS can be used at this point, but i don't have any clue how. Can you advise?
Finally, i found a way...
Bit tricky, but it works. So, this was an IDE bug, where IDE is unable to identify opened "_blank" windows. Here is workaround:
<tr>
<td>storeAttribute</td>
<td>//a[#'Here you can use id/class/href/rel link, etc, for ex: #rel='Register']/#href</td>
<td>href</td>
</tr>
<tr>
<td>openWindow</td>
<td>${href}</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>2000</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>selenium.getAllWindowNames()[1];</td> -- [1] - window to select from array of window names, 0 - it's a main, 1 - 1st opened pop up, 2 - 2nd, etc.
<td>windowName</td>
</tr>
<tr>
<td>pause</td>
<td>2000</td>
<td></td>
</tr>
<tr>
<td>selectWindow</td>
<td>${windowName}</td>
<td></td>
</tr>
<tr>
<td>verifyElementPresent</td>
<td>Verify something here</td>
<td></td>
</tr>
<tr>
<td>close</td> -- close pop up
<td></td>
<td></td>
</tr>
<tr>
<td>selectWindow</td> -- return to main window
<td>null</td>
<td></td>
</tr>