I have automated this using AutoIT in my project. The below is the same code.
public void SaveExcel(string FileName)
{
try
{
#region Excel Export
//Visit this site for Auto IT details
https://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm IAutoItX3 Autoit = new AutoItX3Class();
string WindowsTitle = string.Empty;
if (_Constants.WebDriver == Constants.FireFoxText)
{
WindowsTitle = Constants.OpeningText + FileName + Constants.ExcelExtension;
}
else if (_Constants.WebDriver == Constants.IEText)
{
WindowsTitle = Constants.IEDialogName;
}
int Counter = 1;
Autoit.AutoItSetOption(Constants.AutoITMatchMode, 2);
Autoit.WinWait(WindowsTitle, string.Empty, 2);
while (Counter <= 5)
{
if ((Autoit.WinExists(WindowsTitle) != 0))
{
if (_Constants.WebDriver == Constants.FireFoxText)
{
Autoit.WinActivate(WindowsTitle);
Autoit.Send(Constants.DownKey);
Autoit.WinActivate(WindowsTitle);
Autoit.Send(Constants.TabKey + Constants.TabKey + Constants.TabKey);
Autoit.WinActivate(WindowsTitle);
Autoit.Send(Constants.EnterKey);
break;
}
else if (_Constants.WebDriver == Constants.IEText)
{
Autoit.WinActivate(WindowsTitle);
System.Threading.Thread.Sleep(2000);
//sendiing Alt+s
Autoit.Send(Constants.AutoITAlt_S);
break;
}
}
System.Threading.Thread.Sleep(1000);
Counter++;
}
#endregion
}
catch (Exception Ex)
{
throw Ex;