Handling OS based alert - selenium

I am preparing automated test script for our website. I have a functionality for sending mail. While sending mail outlook produces an alert to accept it to proceed sending mail. But I could not close the alert using selenium and If I manually accept the alert the Selenium script is stopped and the test case fails.
I tried below common code in my script and it didn't work.
Alert alert = driver.switchTo
I know selenium web driver can't handle none web application, but is there a way around it?

Try this,
Popup Dialogs
Starting with Selenium 2.0 beta 1, there is built in support for handling popup dialog boxes. After you’ve triggered an action that opens a popup, you can access the alert with the following:
Alert alert = driver.switchTo().alert();
source :- http://docs.seleniumhq.org/docs/03_webdriver.jsp
maybe this link will help you, try this one also.

Related

File Upload warning Chrome 66 and above to be handled using Selenium Webdriver

Chrome browser allows folder upload (using browse dialog) and recently post version 65 we are seeing a security popup which states that do you trust this site for uploading the files from folder.
This popup is causing the Automation to fail, is there any way to handle it using Selenium? like by using certain capability to bypass it or clicking it?
I already tried Alert accept/dismiss but it doesn't work as it seems that its not an alert. I also tried UIAutomation but it seems that elements are enclosed within the browser without any classname/ID's.
For the time being I have given a workaround of sending Keyboard Tab key and Enter keys.
Is there a proper way to bypass this dialog?
Any help will be appreciated.
Pop-Up Dialog screenshot

Selenium webdriver "Error communicating with remote browser. It may have died" when I run test in parralel

I am working on client side. I have created around 150 test scripts. But during execution, after some script execution, Selenium throws below error and it close the browser. Time is not a fix for this error. It comes when I am executing all the test scripts together in parallel.
The error shows on Google Chrome and Firefox browsers. I am using selenium-server-standalone-2.26.0.jar file and doing execution on FF 13.0.1 version. I have also tried with FF version 14, but I get the same error. My client is not happy with this error because we dont have workaround for this issue.
**Error message:**
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Error communicating with the remote browser. It may have died
I think this will happen when you dealing with popup window.
Example
Working on main window clicking on something leads to open a new popup
switch the control to popup window & do your operations in pop-up
Most of the cases popup will be closed automatically after some action performed in it. (EX : Login with facebook option most of site now a days, after entering user credential no need to close that popup it will be closed automatically after submitting proper credentials)
After this you need to switch the control to main window again otherwise it will throws above exception.
I think your doing some operations without having the control over a window.

handling showModalDialog window in selenium

I am using Selenium- JAVA to automate my application. In my application, when we click on a particular button, it actually opening a window using showModalDialog command. When we open a window using showModalDialog the java-script execution gets suspended till the window gets closed.
Problem No :1
in Internet Explorer(7,8,9), i am getting permission denied error upon clicking. I also tried executing javascript. For this also i got permission denied error. Any idea about this issue?
Problem No:2
In Firefox, i executed the same script and it is working fine. But the problem here is execution is suspended and it will not execute the other commands till the model window gets closed.:( How to solve this issue?
You will have to do modifications in selenium browser bot js-IEBrowserBot.prototype.modifyWindowToRecordPopUpDialogs to handle the modal window-this will help Try this. Or try using webdriver.
Can you post the application HTML you are getting this error on?

Selenium - Handling modal (Child Browser) window in Microsoft Dynamics CRM

I am trying automate Microsoft Dynamics CRM application using Selenium RC, I am unable to handle the modal(child browser) windows. Every time Selenium clicks to open modal window ( selenium.selectWindow("windowName")) I am getting the following error.
There was an unexpected Alert! [A Microsoft Dynamics CRM window was
unable to open, and may have been blocked by a pop-up blocker. Please
add this Microsoft Dynamics CRM server to the list of sites your
pop-up blocker allows to open new windows:
As per the research I tried to add the sever site to trusted sites and also added the site to popup blocker allow list but no gains.
Please direct to me right way of handling it
For some reason Microsoft Dynamics CRM thinks it cannot open the popup window, so it wants to show an alert indicating that. Selenium sees the alert and since it is not expected (you didn't call getAlert()), so the next selenium action (which is selecting the window if I understand correctly) fails.
Maybe you need to wait for the window to actually appear before selecting it?
Check what happens if you set a breakpoint just before the selectWindow() and step through it.
Also try the same steps manually. Do they work?
Remember that selenium uses its own default profile for browsers, so your popup blocker settings may not get through. Which browser is this?
What you can do is accept the popups in the Internet Security, and un-mark the Browse in Secure mode. Close your browser.
Then try it in FireFox and after that do it in Internet Explorer again.

Selenium - dialog box

When the browser launch is initiated by SeleniumRC, a dialog box always comes to ask for username/password to login to our proxy server (however, it is prepopulated with username/password, all has to be done is just press the OK button).
selenium.open("/");
selenium.type("q", "selenium rc");
selenium.click("btnG");
selenium.waitForPageToLoad("10000");
assertTrue(selenium.isTextPresent("Results * for selenium rc"));
// These are the real test steps
//selenium.stop();
After the first command, the dialog box appears and I want to dispose of that dialog box PROGRAMMATICALLY. Any help?
I don't think you'll be able to address this just by using Selenium, that modal dialog is outside the JavaScript boundaries in which selenium works.
The two alternatives I can think of are:
Using WebDriver (soon to be merged into selenium 2.0): has native support over the browser, which allows you to do that kind of stuff.
Using an OS level automation library just for clicking that prompt and you go back to selenium with the rest. The libs available for this things are language dependent, so you will find a lot of different options as Robot for java or pyWinAuto for python.
Update: New alternative:
You can use autoIT as a simple and fast solution under windows.