How to click on ok/cancel button on window dialogue box.

3,604 views
Skip to first unread message

Debasish Dutta

unread,
Jan 17, 2013, 7:55:40 AM1/17/13
to seleniu...@googlegroups.com
Hi All,

I have attached screenshot of the dialogue box. I want to click on the ok/cancel button on the windows dialouge box. there is no xpath of the buttons. by click on the ok button excel file should be opened.How i can overcome this scenario??




Thanks & Regards,

Debasish Dutta
dialoguebox.gif

H D

unread,
Jan 17, 2013, 9:41:35 AM1/17/13
to seleniu...@googlegroups.com
There is no way to click on the Ok / Cancel button. You can try other ways to open this file:
1) Use the direct link to open
2) AutoIT 
3) set the browser settings to download the file automatically without prompt in a particular folder and use the programming language (read Java) to open and read the file.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mark Collin

unread,
Jan 17, 2013, 9:52:19 AM1/17/13
to seleniu...@googlegroups.com

Freddy Vega

unread,
Jan 17, 2013, 10:45:29 AM1/17/13
to seleniu...@googlegroups.com
That is a nice, comprehensive post Mark. Thanks for sharing!

Freddy

Debasish Dutta

unread,
Jan 17, 2013, 11:19:09 PM1/17/13
to seleniu...@googlegroups.com
Hi all,

Thanks for your valuable reply. But anyone having code for this scenario pls share.How i can write code in junit for this scenario.


Thanks
Debasish

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/yGAjjvI3pxMJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

Vikas Garg

unread,
Jan 17, 2013, 11:40:15 PM1/17/13
to seleniu...@googlegroups.com
Thanks Mark for the great share. I would also like to add that there are 2 tools used for the purpose.
1 Autoit
2 Robot class of Java (imported from java.awt package)

I prefer using Robot which is less reliable but platform independent.

There could be the following scenarios that could be handled using Robot
1. Cancel: As we know that when the file download dialogue box appears it means that there is the file which can be downloaded thus we can directly cancel the pop-up.
2. Open: On getting the file download prompt, we can directly open the file.
3. Save: We can save the file for this we have 2 conditions:
             A. Auto Path: In Browser we can make the setting which will save the file at the pre-defined path (Usually in downloads folder).
             B. Manual Path: User will have to give the path for saving the file.

The code is as follows:
try
{
Robot robot = new Robot();
robot.delay(1000);
robot.mouseMove(450, 400);
robot.delay(1000);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ALT);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.delay(5000);
//Bring control back to the main window.
String winHandleBefore = fD.getWindowHandle();
fD.switchTo().window(winHandleBefore);

File screenshot = ((TakesScreenshot)fD).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("C:\\Screenshot\\"+System.currentTimeMillis()+".png"));
}
catch (Exception e)
{
e.printStackTrace();

}

You can make your changes in the code and play around.

--Vikas Garg

Mark Collin

unread,
Jan 18, 2013, 1:42:23 AM1/18/13
to seleniu...@googlegroups.com

If you had read the blog you would have seen that I talked about Java robots and AutoIt J

Vikas Garg

unread,
Jan 18, 2013, 3:41:26 AM1/18/13
to seleniu...@googlegroups.com
Humm I noticed...
Actually I read that long time back thus only remembered the important point of the blog...

Raghu veer

unread,
Aug 18, 2014, 4:57:01 AM8/18/14
to seleniu...@googlegroups.com
Guys 

Try This it worked me on clicking escape button so that the you can close the window dialogue . I used it to close the print dialogue box which pops up automatically in my web application.

                         Robot r = new Robot();
r.keyPress(java.awt.event.KeyEvent.VK_ESCAPE);
r.keyRelease(java.awt.event.KeyEvent.VK_ESCAPE);

Serguei Kouzmine

unread,
Aug 18, 2014, 6:31:27 PM8/18/14
to seleniu...@googlegroups.com

Hello Debasish

I assume you are running Selenium from Windows host. In This case you can use Powershell or C# format of test and

use the code that I posted on codeproject http://www.codeproject.com/Articles/799161/Dealing-with-Powershell-Inputs-via-Basic-Windows-F
section "Selenium Test"  and "Selenium IDE Powershell Formatter" to locate and close the dialog in question or  any Windows window in general by title fragmend and text fragment (e.g. child button text)
The example shown in the article targets save as dialog, but it is clear how to modify it for your particular mime type.
The dialog is found by

Matches button [459550] text : "&Save"
Window process ID is 1104
Window handle is 983844
Window title is Save As
Window match 1


Let me know if you need any help with that.

The  Powershell formatter Selenium IDE plugin is going to be submitted to mozilla dev very soon,

Thanks,

Serguei Kouzmine
Let me know
100.png

Ketam Srinivas

unread,
Jan 24, 2018, 8:46:28 AM1/24/18
to Selenium Users
Hello, I have this dialog issue, how do I click OK here... Using autoIT , I have used robot class, But couldn't worked the below commands.
dialogue box.JPG
Reply all
Reply to author
Forward
0 new messages