1

I am trying to write a java WinAppDriver program which will open Excel, then create a blank workspace, and then it should save that file with a given name.

I can set the file name, but I can't save the file.

Here is my code:

@Test
public void savingWorkbook() {
    ExcelSession.findElementByName("File Tab").click();
    ExcelSession.findElementByName("Save").click();
    ExcelSession.findElementByName("This PC").click();
    ExcelSession.findElementByName("Enter file name here").sendKeys("newFile");              
}

What should I do next in order to save that file? Any solution will be appreciated!

Chandresh Khambhayata
  • 1,748
  • 2
  • 31
  • 60
AniD
  • 21
  • 6

1 Answers1

0

I solved a similar problem recently. Instead of clicking around, I click the the "Open" button in Excel and then used a Desktop session to type full path of file to be saved. After that I send the "Enter" key.

It is understood that once the file selection dialog opens, the control will be at the file path text box. Please see the code below.

internal void FindFilePathOnOpenDialogAndOpenFile(string filePath)
{                       
    System.Threading.Thread.Sleep(2000);
    Desktop.Keyboard.SendKeys(filePath);
    Desktop.Keyboard.SendKeys(Keys.Enter);
}
Naeem A. Malik
  • 995
  • 4
  • 19
  • Hey, I am not getting your solution. Why should I open a file when it's not yet saved. I want to save a Excel file. The workflow should be - Blank Workbook -> File -> Save/Save As -> Selection of location where it will be saved ( This PC ) -> Enter the file name -> Save. – AniD Sep 25 '19 at 11:42
  • The file open dialog and file save dialog have same UI elements. When you click the save button, the file save dialog will open. Just type the full path of your file and press the ENTER key. Your file will be saved. – Naeem A. Malik Sep 26 '19 at 12:06
  • To learn more about WinAppDriver, please see my course here: https://www.udemy.com/course/appium-winappdriver-automation-testing/?referralCode=ED22C3A4CE5BB5E22E53 – Naeem A. Malik Oct 11 '19 at 08:45