Click here to Skip to main content
15,887,346 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Currently i am working on task where i need to automate file download process, for this i am using selenium and Firefox browser.
Issue is this when i am clicking on link to save file, there is file-save dialog opened. Currently i am handling this dialog using sendkeys method, which is working fine but not efficient way because for this purpose that dialog should be top most window. And some time when i am using other things file downloading got skip. Here is my code.
C#
public static void HandleDialogBox(IntPtr hwndl)
        {
            try
            {
                WndSearcher.SetForegroundWindow(hwndl);
                Thread.Sleep(200);
                SendKeys.SendWait("%s");
                //SendKeys.Flush();
                if (hwndl != WndSearcher.GetForegroundWindow())
                    WndSearcher.SetForegroundWindow(hwndl);
                SendKeys.SendWait("%a");
                //SendKeys.Flush();
                //if (hwndl != WndSearcher.GetForegroundWindow())
                //    WndSearcher.SetForegroundWindow(hwndl);
                //SendKeys.SendWait("{TAB}");
                //SendKeys.Flush();
                if (hwndl != WndSearcher.GetForegroundWindow())
                    WndSearcher.SetForegroundWindow(hwndl);
                SendKeys.SendWait("{ENTER}");
                SendKeys.Flush();

            }
            catch (Exception)
            {

                throw;
            }
        }


I want to handle this dialog using winapi
. I have also worked on desktop automation using winapi/pinvoke, and i can get other windows child control (button,checkbox etc) but i am unable to get child control of this file-save dialog.Even spy++ is also not giving me child control of this dialog.
Please help me.
Thanks in Advance.

CP Expert's Opinion Required.
Posted
Updated 2-Feb-16 18:20pm
v2
Comments
Jochen Arndt 3-Feb-16 8:07am    
I have no solution to your specific problem (which may be related to the fact that the file dialog is the standard Windows 'Save As' dialog).

But let my ask:
Why are you using Selenium and FF to perform an automated download?
Wouldn't it be simpler to implement it in your application using the WebClient class?
MuhammadUSman1 3-Feb-16 23:18pm    
Thanks for reply.
I am using selenium to download because i need to log in websites and perform some specific conditions and checks. After that Website provide me download link, when i click on that link then Website return file from server. And this link is also not direct file link. After clicking on link i am getting file in response from website server. Where i am getting direct file link i am also using WebClient class. But i don't know how i can use WebClient for this scenario.
Your response will be very helpful for me.
Thanks Jochen Arndt :)
Jochen Arndt 4-Feb-16 2:58am    
Thank you for your explanation. It may be also useful for others which may help.

I'm sorry that I can't help further. As already noted your problem may be sourced by the fact the dialog is a common Windows dialog (it is provided by Windows and not by the application / FF itself). You may search the web for controlling such common dialogs from other applications.
MuhammadUSman1 13-Feb-16 5:08am    
Thanks for your replies and cooperation. :)

1 solution

@MuhammadUSman1

You can use autoIT for this type of handling because autoIT is good and you can handle easily.

Just you have to run exe file in selenium.
 
Share this answer
 
Comments
MuhammadUSman1 13-Feb-16 5:12am    
Dear @aglom08 i have checked it with AutoIT. AutoIT is also not best way to handle this dialog. Because AutoIT is also not getting dialog child controls like (button/check box).
Thanks for your suggestion and telling me about new things(AutoIT).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900