error Element id not found on Selenium IDE - selenium

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.

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.

Selenium IDE - [error] Element css=button.ng-binding.active not found

I'm trying a basic webpage navigation and each time, I run the recorded scrip it throws the error as defined in the title.
Environment - Selenium IDE - 2.9.1
Browser - Mozilla
<tr>
<td>open</td>
<td>/samplequestions</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=button.ng-binding.active</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=button.ng-binding</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=button.ng-binding</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//button[2]</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=myrate</td>
<td>1000</td>
Could someone help me out what I may have to change ?
As far as now 'ng-binding' is an AngularJS locator and selenium doesn't support it.
If you need to automate Angular application then it is better to you Protrator and using it you can find element like this:
element(by.binding('value'));

how to do if else in Selenium?

I have recorded the log-in into some page with FireFox Plugin Selenium IDE. The recorded result looks like this:
..
....
</thead><tbody>
<tr>
<td>open</td>
<td>/libs/cq/core/content/welcome.html</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/libs/cq/core/content/login.html?resource=%2Fcontent%2Fvrbp%2Fde%2Fpage%2home.html&$$login$$=%24%24login%24%24</td>
<td></td>
</tr>
<tr>
<td>storeElementPresent</td>
<td>id=input-submit</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=input-submit</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>id=searchbox__form-text</td>
<td></td>
</tr>
...
.....
I have saved this Test-case and started it with Selenium IDE. It works fine. It opens the welcome page and then opens the login page and then do the log in.
The problem is now in the case if I am already loged in the page. the Test process hangs on the line ClickAndWait. It does not find the login fields, because I am already loged in.
My Question is: How to tell that it should ignore this step, if I am already loged in?
Is there any unique element you can look at from the log-in page? For example, password and username fields. If they are visible, do a log in, if they are not, you are already logged in.
Hope it helps.
First of all you have to download the plugin flow control for the selenium ide.(https://addons.mozilla.org/en-US/firefox/addon/flow-control/)
Then you have to add some commands to your code to check if the button login exist. So the final code should look like this:
</thead><tbody>
<tr>
<td>open</td>
<td>/libs/cq/core/content/welcome.html</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/libs/cq/core/content/login.html?resource=%2Fcontent%2Fvrbp%2Fde%2Fpage%2home.html&$$login$$=%24%24login%24%24</td>
<td></td>
</tr>
<tr>
<td>storeElementPresent</td>
<td>id=input-submit</td>
<td>present</td>
</tr>
<tr>
<td>gotoIf</td>
<td>present!=true</td>
<td>label1</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=input-submit</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>label1</td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>id=searchbox__form-text</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>

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