Unable to switch to Alert without closing window popup in webdriver - webdriver

Scenario:
Enter a keyword (Position) in a textbox
press Tab or click on the next element
A window popup appears
a list of position matching the criteria will be listed
click the required record
Popup window closes automatically
Alert will be displayed
have click on ok button of alert.
switch to main window and check the position details
Question :- i found many solutions in the site but all are about performing actions on window popup and close the popup then switch to alert or main browser
but my application closes the popup window automatically after selection,hence i cannot use the driver.close() or driver.switchto.defaultContent().
If i dont close the driver (for popup) im not able to identify the next alert displayed after popup.
if i switch directly to mainwindhandle, the alert dismiss is happening instead of accept.
Please anyone who know how to switch from window popup to alert without popup close help is needed...
Thanks ....

If alert dismiss is happening when you are trying to accept it, why don't you use alert.dismiss(), it will probably accept the alert in your context.
When you switch to the popup window, the driver focus is on the popup window. What you might want to do is, just after clicking the required record, switch to the main window then accept the alert.

This must be helpful for you . From your questions, Even after your pop up closes automatically you must be able to access your parent window element by switching back to it. There is no need of driver.close() all the time. Here is the code,
// do something with the pop up and it closes automatically here.
driver.switchTo().defaultContent();
driver.switchTo().frame("your parent window mainframe"));
// try to access your parent window element here

Related

Get active modal QWidget

I need to know in my app if a modal window is opened when I click on a button.
So I'm searching for a method which permits to know if a modal window is opened in my application or no, and which returns the window (or NULL)
Is it possible?
See QApplication's static activeModalWidget

Window.Open without popup-blocker

i want to open a popup window when user leaves tab or closes browser, the available option with me was window.open, but with that, it asks for popup blocker, if it is not enabled, i tried every possible ways to ignore popup-blocker but in vain, i tried onunload, onbeforeunload, but it does not works, i also tried to use modal dialog, before the tab/browser, i used it in onbeforeunload event, but it shows a browsers alert message, which i dont want, my simple requirement is, i need a popup window (if possible) or modal dialog, on the close of tab/browser, but should ignore popup-blocker, i guess with modal dialog, i dont need to worry about popup-blocker, because that wont be the new window, but how i would be handling it, while user closes tab/browser. If any of the above option is not possible, can anyone help me with any other possible alternative, or helpful articles.
Edited Question
i used the below script and with that i can open a new popup window on link click, without popup-blocker interfering in it
$('a[href=http://www.google.com]').click(function(){
window.open(this.href);
return false;
});
then why its not possible for the closing events.
You can't - because that's what popup blockers do: they block popup windows (i.e. calls to window.open or invocations of target="_blank" links) unless it is directly in response to a user mouse action.
Opening popups when a browser window is closed was a common tactic of "pop-under" ads in the early 2000s, and it irritated users, that's why Firefox and IE6's popup blocker block them, and there is no way around it for you unless you ask the user to disable their popup blocker on your site (and I think you'll find most of them will have no idea how to do that).
What are you trying to accomplish anyway? What is the content of this popup that you want the user to see? What other approaches have you tried?
Exact duplicate of your previous question....
I'll post my answer for it here as well though...
Popup blockers are designed to prevent this behavior.
I would suggest using a modal window instead of an actual browser window. I don't think that these get blocked because they are opened within the page itself.
As for the event... You could do something like...
window.onbeforeunload = function whatever() {
//Do code here for your modal to show up.
}
If you are just trying ot give a warning or something you could do
window.onbeforeunload = function showWarning() {
returnString = 'Whatever you want your message to be....';
return returnString;
}
By returning something in the onbeforeunload statement it will show a confirm box with your message in it.
Popup blocker will not block the opening of popups if the javascript code which opens the popup is executed on user's direct action like click, keypress, drag, etc.

MS Windows- Main window no response when show menu on a tray notify icon(use a hidden window to process message)

I implemented an class, this class will show an tray icon. to handle the message from the icon, I have to create a hidden window.
Eevery thing works fine, except if You click outside of the icon, icon will not disappear. I have fixed this by adding code below:
SetForegroundWindow(message-only-hiden-window) // added
TrackPopupMenu()
RESOLUTION:To correct the first behavior, you need to make the current window the foreground window before calling TrackPopupMenu or TrackPopupMenuEx.
Now I get the expect result: the menu can disappear if you click outside of the tray icon.
The problem is now, after the call of SetForegroundWindow(message-only-hiden-window) the main app window will no responding(cannot resize move) I can see the main window actually get those messages in spy++.
Keep this the mind if no call on SetForegroundWindow(message-only-hiden-window). Fine. Except the menu will not disappear.
Anyone has experience on similar situation?
How do you implement an tray icon which has no foreground window at all?
Any kind of help will be appreciated. If you wanna the source code I can email you.
resolved. I have forgot return DefWindowProc in the message only window. tricky

Not able to handle iframe and new window activity

I am not able to handle Iframe popups. In my application when i click on some buttons or link then open iframe pop up. activity which i do on that iframe popup is not recorded in selenium IDE.
select window command also not work.
When i click on link then it open in second window with same title. i am not able to handle that new window's activity.
Please provide me solution if any have.
You need to use the command Select Frame and not Select Window.

How do I prevent a canvas opened from a PopUpButton from closing when it loses focus?

I have a popup button that launches a canvas containing a form that a user can submit. I'm validating this form and displaying an alert when the validation fails. As soon as the user clicks 'OK' on the alert, the canvas launched from the PopUpButton loses focus and closes automatically (its default behavior). PopUpButton._closeOnActivity is private. Any suggestions are greatly appreciated.
Use PopUpManager and a normal button to pop something up manually instead of using a PopUpButton. You can then open and close it when you want to and avoid the default behavior.
var canvas:Canvas = new Canvas();
PopUpManager.addPopUp(canvas, this);
PopUpManager.centerPopUp(canvas);
PopUpManager.removePopUp(canvas);

Resources