Selenium finds element only when I manually click Execute - selenium

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.

Related

verifyAlertNotPresent() in selenium ide halts the execution on failure

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.

Selenium IDE: Selenium script execution stops at the first missing link

I use Selenium IDE to test some webpage content.
My problem is: I have a test case with several 'clickAndWait' instructions on different links. Some links are missing on the webpage. My test case stops at the first missing link. I need my test case to be executed entirely even if a link is missing.
Example:
open | myurl.com |
clickAndWait | mainLink |
clickAndWait | minorLink1 |
verifyTextPresent | text1 |
clickAndWait | mainLink |
clickAndWait | minorLink2 |
verifyTextPresent | text2 |
clickAndWait | mainLink |
clickAndWait | minorLink3 |
verifyTextPresent | text3 |
The problem is, if minorLink1 does not exist, the whole test case is stopped, but I need minorLink2 and minorLink3 to be tested.
Does anyone can help me?
Thanks by advance,
Thomas.
Within the IDE you will not be able to run this as one test if you want it to continue, as the IDE simply follows the instruction order and has to stop when an instruction breaks. You could separate these into separate tests within the IDE, or you could move the operation to one of the supported environments like Java or C#, where you could write logic to avoid a full stop.
You could use loops which I have found to be very effective with ever changing lists where data can start on page one but end up on any page.
Or you could use gotoif command which would look something like this:
<tr>
<td>storeElementPresent</td>
<td>${category_header_obj}</td>
<td>present</td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars['present']==false</td>
<td>exit</td>
</tr>
<tr>
<td>verifyText</td>
<td>${category_header_obj}</td>
<td>Categories</td>
</tr>
<tr>
<td>Label</td>
<td></td>
<td>exit</td>
</tr>

Keeping the focus after opening a new window in the Selenium IDE

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}

Selenium IDE regex gives error "Threw an exception: missing ) after argument list"

In my test case I am trying to capture the dynamic state id from the url of current web page.
My Selenium IDE code is:
storeLocation | myLocation
echo | ${myLocation}
myLocation returns https://stage.abcx.com/ui/States/ManageTitle.ddx? action=view&stateid=76702
storeEval | re=/^sid/;re.exec(${myLocation}) | new
echo | ${new}
The error I keep getting is
[error] Threw an exception: missing ) after argument list
I have searched the net to find what's wrong with my code but could not figure out the issue.
Am new to Selenium and regex would appreciate any help.
Thanks!
You can try to replace
storeEval | re=/^sid/;re.exec(${myLocation}) | new
with:
storeEval | /\\d*$/.exec(storedVars['myLocation']) | new
new will contain all last digits from myLocation. Some info about the difference between ${x} and storedVars['x'] can be found here.

"result is null" error when working around _blank deficiency in Selenium IDE

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.