Selenium IDE not capturing the popup/ Alerts - selenium

I am using selenium IDE to record the commands. I need to test the red rout for login screen. But Selenium is not recognizing the alert coming from the application. Highlighted in bold alert message is not captured by the selenium IDE.
selenium.open("http://192.168.132.244:8080/SampleApp/");
assertEquals("SampleApp", selenium.getTitle());
selenium.type("name=userame", "NoUser"); --USER NAME
selenium.type("name=password", "Password1"); --Password
selenium.click("css=input[type=\"image\"]"); --Login button
selenium.waitForPageToLoad("30000");
Please enter correct Username and Password. -- Alert message
assertEquals("SampleApp", selenium.getTitle());
Please help me out completing this selenium...

Try out this 1
assertEquals("Please enter correct Username and Password.", selenium.getAlert());
Let me know whether working or not.

I've also had success with waitForAlert versus an assert or verify, but as with all your mileage may vary.

USe this command hope this will help you
<tr>
<td>storeAlert</td>
<td>a</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${a}</td>
<td></td>
</tr>

Related

Selenium gmail .. Type text in body

I am new to selenium and would like to send an email using gmail... I am aware if the automation policy of Google and will be using this mainly for testing and sending email to small number of friends , so please don't answer with ' it violates policy so don't do it ..' Etc
I tried the solution given here but its not working. The body of email is written as HTML div in body of email rather than textarea.
Can someone give me xpath , command , and value fields.
I would also like to know why the example given is not working as I am unable to understand it.
I am using https://mail.Google.com/mail/u/0/?view=cm to directly compose mail rather than the compose dialogue of email.
After login please use Thread.sleep(10000) and then fine element as per below :
//DO LOGIN
Thread.sleep(10000);
driver.get("https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=1");
Thread.sleep(10000);
//XPATH FOR BODY
driver.findElement(By.xpath("//*[#id=':nz']")).sendKeys("TEST DATA IN BODY");
I have tested and above code is working. Actually after login it takes some time to load so elements are not always visible immediately so I have used thred.sleep();
This worked for me. I don't love it.
<tr>
<td>type</td>
<td>id=:om</td>
<td>some#email.com</td>
</tr>
<tr>
<td>type</td>
<td>id=:p1</td>
<td>subject text</td>
</tr>
<tr>
<td>type</td>
<td>//input[#name='body']</td>
<td>fdhh</td>
</tr>

Shifting focus to a new popup window that has a null ID and name

I apologize if this question is redundant - I've seen a number of similar posts on this and other sites but none of them presented a solution that helped me.
I am using Selenium IDE to record a script that clicks a link (which opens a new window with a .shtml extension). I then need to switch focus to the new window and hit the save button to download a PDF.
I don't understand exactly how this works, but the url of the popup window is some generic url (https://www.theice.com/marketdata/reports/datawarehouse/ConsolidatedEndOfDayReportPDF.shtml) that hosts whatever report you generate on the previous page (https://www.theice.com/marketdata/reports/ReportCenter.shtml#report/142). If you try an openWindow command on the new URL it won't generate the report, you must open it through a link on the first page.
I want to refocus selenium to the new popup through selectWindow or selectPopup, but the issue is that the popup has no name, ID or title. Does anyone have a suggestion on how to avoid this issue?
Thanks,
Have not tried this out myself, but you could use this to find the window names and switch to it.
<tr>
<td>storeAllWindowNames</td>
<td>names</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${names}</td>
<td></td>
</tr>.
<tr>
<td>selectWindow</td>
<td><the name you find out></td>
<td></td>
</tr>.
You can try with storeAllWindowIds,storeAllWindowTitles. These three methods should return an array of windowids, something like this , bJHBGug2u8

Selenium - Handling a Popup [duplicate]

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>

Automating Gmail with Selenium

i want to use selenium to click on a specific button !
the send button on gmail, the standard version and not the basic html version
i tried
<tr>
<td>selectFrame</td>
<td>c16nfgbb415qzj</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//div[#id=':v9']/b</td>
<td></td>
</tr>
didnot work
give me python code please and not html
Thanks
You can't record a script in Selenium and play it back using standard Google Mail. Most of the HTML names/IDs/classes in standard Google Mail are unpredictable.
You'd have to use xpath-based targets with indices e.g. //div[2]/div/div[3]. This has a high-dependency on the structure of the HTML being served by Google Mail. As soon as it changes, you'll need to modify your script.
The basic HTML version is predictable enough to just record and replay a script. You didn't say why you don't want to use that.

Selenium IDE - There was an unexpected Confirmation!

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)