I have a following problem. After Submit some date on page I have a modal dialog like on the picture:
I want to click "ENTER" to go through that modal but it does not work.
I have following code:
driver.FindElement(By.CssSelector("input.submit")).Click();
Actions action = new Actions(driver);
action.SendKeys(OpenQA.Selenium.Keys.Enter);
After click on continue manually test go back to next page. I must go through this modal to continue the test. Any ideas how to solve this problem?
I found a solution by following code:
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
It works for me.
In java:
Alert alert = m_driver.switchTo().alert();
alert.accept();
Related
I'm trying to code below script for clicking OK button through script but fail to do it.
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
What am I doing wrong, Correct me.
I found an excellent nuget package, AutoItX.Dotnet, that will handle popups in chrome.
Link to nuget package - https://www.nuget.org/packages/AutoItX.Dotnet/
Please use the code below as a reference
//This code snippet will fix your specific issue
AutoItX.WinWait("Untitled - Google Chrome", "", 2);
AutoItX.WinActivate("Untitled - Google Chrome");
AutoItX.Send("{Enter}");
//Use code below to switch between buttons/text boxes within the popup
//And send text to text boxes within the popup
AutoItX.Send("{TAB}");
AutoItX.Send("HelloWorld");
You may have to test a bit further to see what keys you need to pass to make this code work seamlessly with each specific popup that you wish to interact with.
JavascriptExecutor should work for you. Just take care that you should execute it before clicking the event which invoke alert.
C# Code
IWebDriver driver; // assume assigned elsewhere
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.confirm = function(msg) { return true; }");
Java Code
((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return true; }");
Note :- do not use it after clicking on event which invoke alert confirmation box. Above code by default set the confirmation box as true means you are accepting/click on ok on all confirmation box on that page if invoked
Hope it will help you :)
I have one asp.net page , it consists of some controls along with a close button. If the user clicks on the close button, it will open ModaldialogBox with one text box for entering closing reason. Once the user enters the reason and clicking on the save button, the modal popup shows the alert message and close the modal popup. The existing code for this is shown below.
this.Page.ClientScript.RegisterStartupScript(GetType(), "close", "alert('" + Message + "');var xWin=window.dialogArguments;xWin.location.replace(xWin.location);window.close();", true);
My requirement is that, once the user click on the submit button, I have to navigate to the dashboard page after closing the modal popup window.
I had tried window.location.href after the window.close(), It will open another window and displyed the page. But it should navigate from the existing asp parent page. Please help me for resolving this issue.
Thanks in advance
redirect the parent window with following code
window.opener.parent.location.href = 'dashboardurl';
I am working on mvc2 and i'm trying to open from javascript in a new window something.
if i only use inside the js function window.open("action/action/"+param) like this
function(){
window.open("action/action/"+param);
}
it works perfectly and the browser does not warn me that it is a new popup that i'm opening.
But if i make an ajax call before the window.open, the browser tells me that is a new popup and if i accept it.
if (json.data && json.data.URL)
{
window.open("action/action/"+param);//opens in a new window only if i accept popups
}
how can i make it work without the browser considering it as popup?
You can't popup a window "randomly" it needs to be right after the user has clicked something or did an action so that the browser doesn't think it's a random ad popup.
The window has to open as a direct result of the user's input. For example, you could open a new window inside a click handler. It's not full proof by any means, but it's one measure the browser can take to try and prevent unwanted popups.
I am trying to automate one website, in my project after clicking on 'submit' button, one alert message with ok button will come. I want to click that ok button.
I tried with these two codes seperatly but these are not working
AlertDialogHandler AlertDialog = new AlertDialogHandler();
ie.AddDialogHandler(AlertDialog);
ie.Button(Find.ByValue("Submit")).ClickNoWait();
AlertDialog.WaitUntilExists();
AlertDialog.OKButton.Click();
ie.WaitForComplete();
ie.RemoveDialogHandler(AlertDialog);
var AlertDialogHandler = new AlertDialogHandler();
using (new UseDialogOnce(ie.DialogWatcher, AlertDialogHandler))
{
ie.Button(Find.ByValue("Submit")).ClickNoWait();
AlertDialogHandler.WaitUntilExists(50);
var message = AlertDialogHandler.Message;
AlertDialogHandler.OKButton.Click();
ie.WaitForComplete();
}
While using these two codes, I got the same exception 'dialog not available within 30 seconds'.
Any help will be deeply appreciated. Thank You :)
This has happened with me a couple of times when I had multiple browser windows open and I was trying it out.
The solution at that time was to close all instances of IE, close NUnit / VS and start over again, and it worked like a charm. However, I was using a ConfirmDialogHandler and not an AlertDialog Handler.
If that does not help you might want to try adding the following before you fire up your browser instance.
Settings.AutoStartDialogWatcher = true;
Settings.AutoCloseDialogs = true;
I'm not familiar with WatiN, but here's another SO post that might help:
WatiN seems to not find JavaScript alert
There is a way to perform this without watin:
See my post:
Need a way to perform auto confirm for firefox or any other browser popup's
this is slightly unrelated but AlertDialogHandler's don't work for Firefox but there is a workaround...
http://pastebin.com/ZapXr9Yf
I need to open a new window from code-behind on post-back if a specific radio button is selected.
Is there any way to do this?
Thank you.
You can use RegisterStartupScript to send a window.open script to run once the page has loaded.
However, this will cause the majority of popup blockers to get in your way.
I think this should work ;-)
Add some javascript to your radio button to open a new blank window before you post back. This makes it so popup blockers won't block your popup, since it's opened in response to a users click. See this link for how to do this part.
Then, allow the postback to happen as normal and on page load, register a startup script to tell your already existing window to go to a new url.
String script = "window.open('popupPage.aspx', 'myPopup')";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someId", script, true);
Note that in javascript, when you call
window.open(url, 'myPopup')
if a window already exists with that name it'll return it instead of creating a new window... So your popup won't get blocked!
You will need to run javascript on postback
Simple sample of RegisterStartupScript:
RegisterStartupScript("id1", "<script type=\"text/javascript\">alert(\"I'm from JavaScript.\");</script>");
New windows can be very sketchy, depending on the content that you need to present you might consider using an in window pop-in if you will. You will avoid pop-up blockers that way. If you can give more details we can give better answers.