I have a button that displays Javascript confirmation popup. This is a part of my test case:
<tr>
<td>clickAndWait</td>
<td>buttonId</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>Object has been deleted</td>
<td></td>
</tr>
It works as expected: OK is clicked automatically on a popup and verifyTextPresent return true. Still, I get [error] There was an unexpected Confirmation! in the log and test case fails.
Any suggestions?
Summary: In the IDE use storeConfirmation.
You have to consume confirmation dialogs. Otherwise the Selenium test will fail.
From the Java Selenium RC API Selenium.html.getConfirmation method:
If a confirmation is generated but
you do not consume it with
getConfirmation method, the next Selenium
action will fail.
Edit:
storeConfirmation consumes the confirmation as well.
storeConfirmation ( variableName )
Retrieves the message of a JavaScript confirmation dialog
generated during the previous action.
If a confirmation is generated but you do not consume it with
getConfirmation method, the next Selenium
action will fail.
I encountered the same problem, and I solved it like this:
chooseOkOnNextConfirmation
click buttonId
assertConfirmation
This makes my test run green in my Selenium IDE.
The code to do this is:
<tr>
<td>chooseOkOnNextConfirmation</td>
<td></td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>ctl00_CPHMain_ucFormDMS_grdDocumentList_ctl00_ctl04_btnDelete</td>
<td></td>
</tr>
<tr>
<td>assertConfirmation</td>
<td>Areyousureyouwanttodeletethisdocument?</td>
<td></td>
</tr>
using selenium.chooseOkOnNextConfirmation is correct but insead of using this alone use
selenium.click("xpath=//button");
selenium.getConfirmation();
selenium.chooseOkOnNextConfirmation();
Here it will first click on the button and get the confirmation , then it would click OK from that confirmation
In Selenium IDE you can use waitForConfirmation(pattern)
Related
I want to read two elements from a web page, store their text in two variables and open a new window with an URL dependent of the variables' contents.
This is what my Selenese HTML looks like:
<tr>
<td>storeText</td>
<td>//dd[2]/strong</td>
<td>str</td>
</tr>
<tr>
<td>storeText</td>
<td>//dd[3]/strong</td>
<td>plz_ort</td>
</tr>
<tr>
<td>echo</td>
<td>${str} ${plz_ort}</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>500</td>
<td></td>
</tr>
<tr>
<td>openWindow</td>
<td>https://www.google.de/?q=${str}%20${plz_ort}</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>name=btnG</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=lu_map</td>
<td></td>
</tr>
I am using the echo to manually verify that the textual content of the elements has correctly been read. However, the Selenium IDE throws an error at the openWindow step:
[warn] Opening window '_blank', which is not a real window name.
Randomizing target to be: selenium_blank19164
[error] Unexpected Exception: TypeError: result is null.
I have also tried to give the openWindow command a window name in the Value field (e.g. "random", "_blank", "foobar"), but this didn't work either.
The strange thing I wonder about: when I manually execute the command where the IDE fails it perfectly opens my window, even if still a warning is issued:
[warn] Opening window '_blank', which is not a real window name. Randomizing target to be: selenium_blank23341
Debugging in the IDE shows that the error message also comes form the openWindow command.
I did not find related questions on SO. Any help how to further debug or fix this is very much appreciated.
Problem solved. I was using Firefox' pop-up blocker and did not pay attention to the original page. Adding the AUT to the exception list fixed the problem for me.
How to do with the Element ID changing repeatedly in selenium IDE ?
this comes when I click in the button and refresh the page and click it again !
<tr>
<td>open</td>
<td>/FEP/LoginHandlerServlet.htm</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=a2uPu0</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=tU9Pu0</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=qXCPu0</td>
<td></td>
</tr>
My web application develop with ZK ( Zkoss)!
any idea?
Try finding the element by xpath or by link text, not by ID.
by linktext:
driver.findElement(By.linkText("Link text")).click();
by xpath:
findElement(By.xpath("your xpath")).click();
I gouess in YOur situation linktext would be better.
This is a common problem that I find with certain web frames (e.g. Wicket) where the HTML id changes each time the web page is rendered. If the development team is on board with automating your tests, then there is typically a way to make these ID's static, solving your problem. Otherwise, as mentioned previously you have to use some other identifying tag.
Here is a good website to get you started on all of the available options that you have at your disposal.
I am trying to run a test recorded using selenium IDE. The following html is generated by the IDE
<tr>
<td>clickAndWait</td>
<td>css=span.blt-txt</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=pt1:svMenu:np1:6:cni1::disclosureAnchor</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=pt1:r5:0:mr1:gts1:gts_pc1:itFilterFieldValue::content</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=pt1:r5:0:mr1:gts1:gts_pc1:cil1::icon</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=pt1:r5:0:mr1:gts1:gts_pc1:tt1:0::di</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=pt1:r5:0:mr1:gts1:gts_pc1:tt1:1:astTreeSNo</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=pt1:r1:0:rAstDtl:0:cb4</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id('pt1:ptGeneric:ot1::_afrTtxt')/x:div/x:h1</td>
<td></td>
</tr>
When I run the test/execute command I get an error saying [error] Element id=pt1:r5:0:mr1:gts1:gts_pc1:tt1:0::di not found
Any ideas how I can fix this?
the id seems to be generated try not to use this id or use contain
(try to use other xpath)
i would use only the last word of the id (you need to check it)
3.you can highlight to see where you are
example for contain
./li[contains(.,'Model')]]
Using generated ID in a testcase is usually a bad idea. When the server restarts / data change, these IDs tend to change, too.
Anyway, your problem seems to be the classical problem with timing. Are your elements AJAX-loaded when something is clicked / after a page change? If yes, Selenium tries to click them before they get fully loaded. You should use waitForElementPresent before you click on the element that causes trouble.
Generally, using Selenium IDE for AJAX-heavy pages uses to get hard very easily. Consider switching to manual Selenium RC writing or, even better, Selenium WebDriver. You can have the best of both worlds - first click through your test in IDE, then export your code to WebDriver in any language, make required changes, add waits (implicit are often enough), you're done.
While recording through Selenium IDE, When a pop up window opens it is not getting recorded. "At the time of executing an error message is displayed.Please help me out.
If that pop up window has name, like opening from javascript window.open(URL, name).
Then it is possible to add the command to check the content of the popup. Like following command:
waitForPopUp | winId | 30000
selectWindow | winId
...
close
However, if the window has no name, like opened from <a target="_blank"> then you are out of luck.
Go to http://wiki.openqa.org/display/SEL/Selenium+Core+FAQ#SeleniumCoreFAQ-HowdoIworkwithapopupwindow%3F for further details.
Selenium IDE does not recognize any kind of popup, either you have to add it manually or Use Selenium RC, pop are handled there.
You must use the command WaitForPopUp and value 30000
Try this and record properly.
Unfortunately Selenium IDE record/replay doesn't always record everything. It tries it best to do that but if there is an AJAX call it may not record this.
Best practise is to use the record to get a the main body of the test and then adapt it to handle the parts that it missed
I suggest manually adding those extra lines to your tests.
Selenium IDE can record popup, below is my code I record Popup through selenium, check and let me know
<tr>
<td>click</td>
<td>id=edit-legal-accept</td> // click on this then pop up is open
<td></td>
</tr>
<tr>
<td>waitForPopUp</td>
<td>CtrlWindow</td>
<td>30000</td>
</tr>
<tr>
<td>selectWindow</td>
<td>name=CtrlWindow</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>Terms And Conditions</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>Terms & Conditions of Use</td>
<td></td>
</tr>
<tr>
<td>close</td>
<td></td>
<td></td>
</tr>
<tr>
<td>selectWindow</td> // This command used to select our main windows
<td>null</td>
<td></td>
</tr>
Moving my Cursor to a Element in webpage opens a drop down menu but this element is not clickable whenever user moves cursor over this element a dropdown menu opens
Example can be Like in this webpage(Stackoverflow page) when you point your cursor to your user name located at top it opens a drop down menu/window
But using Selenium i m not able to replicate this
Using Selenium not able to open this Drop down menu
used click, focus and mouseOver for this but didn't get any success
Please Help
I found the reason for my problem
Actually in my site dropdown operation is defined in CSS and Selenium does not interact with CSS.
Here is how i can select the the "reputation" link from the menu which is displayed when you hover over the triangle next to your name on Stackoverflow.
You must ensure you wait for the menu to be visible before trying to click a link in it.
<tr>
<td>open</td>
<td>/questions/6870807/selenium-not-able-to-interact-with-a-specific-element-in-a-web-page</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.profile-triangle</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>link=reputation</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=reputation</td>
<td></td>
</tr>