I'm having a problem retaining the focus after using the openWindow command in the IDE. This problem only applies when a second test case within the same test suite tries to interact with the newly-opened window. For example, I have a test suite consisting of separate test cases to do the following:
Log into site A
Enter some transactional data
Submit the transaction for approval
Open a new window and log into site B
Approve the transaction in site B and close the window
Continue processing the transaction in site A
If I do the test case 5 "site B" actions in the same test case as the "openWindow" (ie. merge test cases 4 and 5) then all commands execute without error. If I do the same actions in a different test case then the new window loses the focus and all Selenium commands are directed back to the original window.
The interesting part of this is trying to identify and reselect the "new" window in step 5.
Executing "selectWindow name=siteB_URL" in test case 5 results in the error message "Window does not exist. If this looks like a Selenium bug...".
I then figured I'd call storeAllWindowNames and echo the results to at least see the window names Selenium knows about at various points. If I do this as the last two commands in test case 4 I get the expected result - "echo ,siteB_URL" is logged. If I do the same thing as the first two lines in test case five I get "echo ". This is the part that gets me - simply changing test cases seems to lose the reference to the new window.
Has anyone come up with a workaround or solution to this problem in the Selenium IDE?
I've spent several hours this morning scouring the web and various forums looking for suggestions to no avail.
Thanks in advance,
Glenn
4-7-12 - Update - here's a simplified example of the scenario above:
[info] Executing: |openWindow | http://www.google.com.au | google2 |
[info] Executing: |selectWindow | google2 | |
[info] Executing: |storeAllWindowNames | allWindows | |
[info] Executing: |echo | ${allWindows} | |
[info] echo: ,google2
[info] Changed test case
[info] Executing: |storeAllWindowNames | allWindows | |
[info] Executing: |echo | ${allWindows} | |
[info] echo:
[info] Executing: |selectWindow | name=google2 | |
[error] Window does not exist. If this looks like a Selenium bug, make sure to read http://seleniumhq.org/docs/04_selenese_commands.html#alerts-popups-and-multiple-windows for potential workarounds.
Have you check it with following commands?
selectFrame | relative=up
selectFrame | iframe name
Try with option:
selectWindow()
Just provide the window title name within ().
For Ex:
Window Title is Testing, then
command : selectWindow
title : Testing
To know the title of the newly opened window follow the steps:
Go to the new window
Right click->view page source
Press ctrl+F.
Type title and search.
You will get the title of the new window.
I hope this helps...
Thanks
Sathiya
//on the original window...
command: store window handle
target: myVar
//...do whatever...
command:select window
target: handle=${myVar}
Related
I am running Selenium IDE and trying to write a while loop to open a new chrome window after closing one. I had several attempts with select windows but still unable to run the loop repeatedly.
Here is what I have:
Error:
while on ${var}<=2 Failed:
A window was not selected after closing the previous one, aborting playback.
This error appears because of wrong iterator. execute script | ${var} +1 | command doesn't increase variable var. This command should be replaced with execute script | return Number(${var}) +1; | var
Also You forget to select root window after closing new tab. So after the 10th command should be added select window | handle=${root} |
I am trying to create a random number generator:
Command | Tgt | Val |
store | tom | tester
store | dominic | envr
execute script | Math.floor(Math.random()*11111); | number
type | id=XXX | ${tester}.${dominic}.${number}
Expected result:
tom.dominic.0 <-- random number
Instead I get this:
tom.dominic.${number}
I looked thru all the resources and it seems the recent selenium update/version has changed the approach and I cannot find a solution.
I realize this question is 2 years old, but it's a fairly common one, so I'll answer it and see if there are other answers that address it.
If you want to assign the result of a script run by the "execute script" in Selenium IDE to a Selenium variable, you have to return the value from JavaScript. So instead of
execute script | Math.floor(Math.random()*11111); | number
you need
execute script | return Math.floor(Math.random()*11111); | number
Also, in your final assignment that puts the 3 pieces together, you needed ${envr} instead of ${dominic}.
I have written a script to Verify that alert is not present using verifyAlertNotPresent command. Using this command as I know execution should not stop even if alert is present and should continue but it halts the execution. My script is given below.
forXml | file:///E:/XML files/NAA_StateZip.xml
open |
clickAndWait | link=NAA Click & Lease
type | name=_OWNER | sdfsdf
type | name=OWNERFAX | 1234556
fireEvent | name=OWNERFAX | blur
verifyAlertNotPresent | Error: Invalid input format Please re-enter area code and phone number |
close
selectWindow | null
endForXml
When I am running this script Log shows this.
[info] Executing: |type | name=OWNERFAX | 1234556 |
[info] Executing: |fireEvent | name=OWNERFAX | blur |
[info] Executing: |verifyAlertNotPresent | Error: Invalid input format Please re-enter area code and phone number | |
[error] true
[info] Executing: |close | | |
[error] There was an unexpected Alert! [Error: Invalid input format Please re-enter area code and phone number]
[info] Test case fail
Please provide solution to this as I want to run this script for set of data.
To handle alerts using Selenium IDE, you will have to use 'assertFoo(pattern)' function. If you fail to assert the presence of a pop-up your next command will be blocked and you will get an error. Look at the Docs.
I need to click on the button automatically. Code:
<tr>
<td>click</td>
<td>css=button</td>
<td></td>
When I click "Play current test case" it does not finds the element. But when I click "Find" after that - it does, and if I click Execute - it clicks on it!
Log:
[info] Executing: |click | css=div.sometag > p | |
[info] Executing: |pause | | 2000 | // Same error with pause & without it
[info] Executing: |clickAndWait | css=button | | // Auto executing
[error] Element css=button not found // Fails
[info] Executing: |click | css=button | | // I click on "Execute" manually - OK!
Why?
Have you tried to insert "waitForElementPresent|css=button|" before the click statement? This might help.
You actually need to use the class selector. So either div.button or .button, otherwise selenium probably is looking for an ID or an element name.
You could also try using a different type of locator, such as ID or XPath.
If we were able to see the HTML of the page you are interacting with, we could provide exact examples.
Using a workaround to be able to check the contents of a new tab, I get unexpected results. If I play the test case, the following line fails:
storeEval | javascript{"selenium.browserbot.getCurrentWindow().open('', 'my_window')"} | my_window
with the following error message:
[error] Threw an exception: result is null
The following alternative statements show the exact same symptoms:
getEval | window.open("", "my_window")
getEval | selenium.browserbot.openWindow("", "my_window")
Now, if I double-click it, it doesn't fail, but it opens up a new window, which I think the original solution didn't intend (the next step is to click on a link in the parent window, after all). At this point I can click on the parent window, manually run the next step to launch the link, manually change back to the child window (selectWindow | my_window says it can't find that window), and manually run each of the following steps to check the contents of the new window.
How do I proceed from here to make the test properly automatic?
Update: There is a built-in action for opening windows, but it also fails. Maybe this verbatim log output can shed some light on what's going on:
[info] Executing: |store | license_window | windowName |
...
[info] Executing: |openWindow | | ${windowName} |
[error] Unexpected Exception: fileName -> chrome://selenium-ide/content/recorder.js, lineNumber -> 74
The relevant lines from recorder.js:
66: window.open = function(url, windowName, windowFeatures, replaceFlag) {
...
74: if (result.wrappedJSObject) {
75: result = result.wrappedJSObject;
76: }
It seems that your browser doesn't allow pop-up for your web site. Go to options > Content > Exceptions for block pop-up windows and add your web site address.