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
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 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();
Got problem with opening custom context menu using advanced user interactions API in Selenium 2 (http://code.google.com/p/selenium/wiki/AdvancedUserInteractions).
Here is C# code:
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.flickr.com/photos/davidcampbellphotography/4581594452/");
IWebElement photoDiv = driver.FindElement(By.Id("photo"));
Actions actions = new Actions(driver);
var context = actions.ContextClick(photoDiv).Build();
context.Perform();
Still this code doesn't open context menu but simply clicks on the image.
Still many other interactions work fine, like those at this blogpost.
I'm using Firefox 5 on Windows XP, Selenium version 2.2.
Thanks in advance for any suggestions how to make it work.
UPDATE:
However, the code from here does the same (left click instead of context click).
ILocatable loc = (ILocatable)photoDiv;
IMouse mouse = ((IHasInputDevices)driver).Mouse;
mouse.ContextClick(loc.Coordinates);
mouse.MouseMove(loc.Coordinates, 15, 15);
Looks like a bug.
Have you tried using a robot click, Although they're not the most efficient way of doing so, but as long as the browser window is the top window it'll click the co-ordinates you set
Robot robot = new Robot();
robot.mouseMove(650, 590);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Maybe this will help you :-)
This seems to be that bug.
It is stated in the user group here, though the bug is about double click.
I am testing a web app where i delete an item from a list. Upon clicking on delete, the app asks for confirmation. Selenium IDE detects it as a confirmation box. When I run the code thro' the RC (C#), it even catches the confirmation-box, executes the click of delete button on that confirmation box, but, the confirmation box is never visible on the screen. Further, it only clicks on the delete button; the item doesn't get deleted. I tried it manually, works fine.
Please help, I'm new to Selenium and tried to find the answers at multiple forums without any success.
Here's the code:
string confirmation;
for (int second = 0;; second++) {
if (second >= 60) Assert.Fail("timeout");
try
{
confirmation=selenium.GetConfirmation();
if ((confirmation == " Delete confirmation message")) break;
}
catch (Exception e)
{
PrintLog("Error while waiting for confirmation. Error: "+e.Message);
}
Thread.Sleep(1000);
}
try
{
Assert.IsTrue(confirmation == "Delete confirmation message");
}
catch (AssertionException e)
{
PrintLog(e.Message);
}
selenium.FireEvent("//a[#id='btnOkConfirm']","click");
After the last statement, the selected item must get deleted and page should refresh, but, nothing happens. All I can see is "Javascript:;" written in the status bar of the firefox window. I guess its problematic to get javascript hrefs working in selenium-rc.
Thanks,
Vamyip
There are a number of commands to deal with JavaScript confirmations. Selenium will by default choose 'OK' at a confirmation, unless you send the chooseCancelOnNextConfirmation command. In order to consume the confirmation you will need to use the getConfirmation command.
Selenium reference for above commands:
http://release.seleniumhq.org/selenium-core/1.0/reference.html#storeConfirmation
http://release.seleniumhq.org/selenium-core/1.0/reference.html#chooseCancelOnNextConfirmation
http://release.seleniumhq.org/selenium-core/1.0/reference.html#chooseOkOnNextConfirmation
Additionally, if your click command is not showing the JavaScript confirmation you might find that the appropriate event is not being fired. You could try using the mouseDown and mouseUpcommands, or the fireEvent command.
Lately, I've discovered that this behavior is occurring due to the architecture of selenium(more precisely, its javascript based core). when I do the test manually, keeping the selenium IDE open, this behavior is replicated. So, I think there's no immediate solution to this problem right now. Will post here if I find a workaround.
Thanks to Dave for replying.
Update: The development team informed me that a javascript function is not being called with selenium IDE running alongside. This indeed is a problem with Selenium's Javascript core.
Thanks to everybody who took time to respond to this question.
Regards,
Vamyip
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.