Hi,
I'm trying to do a sample workflow on Microsoft Excel 2016.
Workflow:
1.Launch MS Excel.
Issue :
MS Excel getting launched but couldn't click on "Blank workbook" button and test getting failed at below screen and it remains (Excel not getting close) ;

When I re-run the test for the second time, the test begins from the existing screen (above screen) and second time "Blank workbook" button getting clicked and test continuous and run successfully.
My code snippet :
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import io.appium.java_client.ios.IOSDriver;
public class ExcelISDPOC {
private static IOSDriver Excel;
@Test
public void test() throws InterruptedException {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("app", "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE");
Excel = new IOSDriver (new URL("http://127.0.0.1:4723"), cap);
// Excel.manage().window().maximize();
Excel.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
Thread.sleep(3000);
Excel.findElementByName("Blank workbook").click();
Thread.sleep(3000);
Excel.findElementByName("Insert").click();
Thread.sleep(3000);
}
}
Console :
ERROR FAILED CAUSE:
org.openqa.selenium.NoSuchWindowException: Currently selected window has been closed (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 52 milliseconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'LKCONVSELVARA01', ip: '192.168.8.101', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities [{app=C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE, platformName=iOS, platform=ANY}]
Session ID: EA27B09A-E89F-41A0-96FC-A320C90639FA
*** Element info: {Using=name, value=Blank workbook}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_131]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_131]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_131]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_131]
WinAppDriver log :
==========================================
POST /session/EA27B09A-E89F-41A0-96FC-A320C90639FA/element HTTP/1.1
Accept-Encoding: gzip,deflate
Connection: Keep-Alive
Content-Length: 41
Content-Type: application/json; charset=utf-8
Host: 127.0.0.1:3073
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_131)
{"using":"name","value":"Blank workbook"}
HTTP/1.1 400 Bad Request
Content-Length: 102
Content-Type: application/json
{"status":23,"value":{"error":"no such window","message":"Currently selected window has been closed"}}
Could you please help me to solve this problem.
cc: @yodurr
confirmed there's a bug here. Seems to be an internal timing issue within winappdriver.
I'm running our current code in development and this problem has gone away. Marking this as one that will be fixed in the 1.0 release.
Thanks @yodurr. When I try with below code, I can go through the test scenario without any error.
//Excel.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
Excel.launchApp();
But if try this "launchApp()" method for any other app like notepad, it open's two instance of notepad.
that's an interesting workaround, and glad you can run tests now. You shouldn't have to call launchapp. Hoping to release v1.0 later this month.
Great @yodurr. All the best for a successful release ;)
Hi @vijay44,
The first error you encounter is due to the way Microsoft Excel launches. When Excel is not yet launched and you create a new session to launch it, Excel will start few processes and potentially show multiple windows like a splash screen. At this point, Windows Application Driver takes the first valid application window (the splash screen) and treat it as the main window to interact with. As soon as the splash screen is dismissed, any subsequent commands you send to it will result in no such window error which you saw.
When you wait enough time until the main window containing the Blank workbook is displayed and invoke launchApp() API, WinAppDriver will re-launch the application based on the initial information (capabilities) you provided during session creation. In the case of your version of Microsoft Excel configured the way it was, it simply highlighted existing instance instead of creating a new instance. As a result, the main window that is now displayed is set as the main window as it is the first valid main window at this point belonging to the process.
Now that we have the right explanation of what happened, you can use it as a working workaround as long as you configured your Microsoft Excel the way it was. In fact this is a very good use of the launchApp() in this particular condition. Alternatively, you can also use SwitchTo() API to switch to the right main window once the correct main window is displayed. Below is a sample on how to switch window if your session is pointing to a wrong window such as the splash screen:
```c#
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", YourAppId);
WindowsDriver
Assert.IsNotNull(session);
// Identify the current window handle. You can check through inspect.exe which window this is.
var currentWindowHandle = session.CurrentWindowHandle;
// Wait for 5 seconds or however long it is needed for the right window to appear/for the splash screen to be dismissed
Thread.Sleep(TimeSpan.FromSeconds(5));
// Return all window handles associated with this process/application.
// At this point hopefully you have one to pick from. Otherwise you can
// simply iterate through them to identify the one you want.
var allWindowHandles = session.WindowHandles;
// Assuming you only have only one window entry in allWindowHandles and it is in fact the correct one,
// switch the session to that window as follows. You can repeat this logic with any top window with the same
// process id (any entry of allWindowHandles)
session.SwitchTo().Window(allWindowHandles[0]);
For the benefit of others, below is the snippet of your workaround that will work if the application under test enforce single instance and will simply bring up already launched instance when being re-launched.
```c#
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", YourAppId);
WindowsDriver<WindowsElement> session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
Assert.IsNotNull(session);
// Wait for 5 seconds or however long it is needed for the right window to appear/for the splash screen to be dismissed
Thread.Sleep(TimeSpan.FromSeconds(5));
// When the application uses pre-launched existing instance, re-launching the application simply update
// the current application window to whatever current main window belonging to the same application
// process id
session.LaunchApp();
Thanks @timotiusmargo. The above explanation is more helpful and interesting .
If the excel is opened before the driver does it, the click on 'Blank workbook' works fine.
Hi @srinigowda,
Yes it makes sense since the issue was caused by the Excel splashscreen that was mistakenly taken as the main application window. If the Excel main window is fully opened and simply refocused on session creation, it will be correctly taken as the main application window and clicking on any button should indeed work.
Hi @vijay44,
The first error you encounter is due to the way Microsoft Excel launches. When Excel is not yet launched and you create a new session to launch it, Excel will start few processes and potentially show multiple windows like a splash screen. At this point, Windows Application Driver takes the first valid application window (the splash screen) and treat it as the main window to interact with. As soon as the splash screen is dismissed, any subsequent commands you send to it will result in no such window error which you saw.
When you wait enough time until the main window containing the Blank workbook is displayed and invoke
launchApp()API, WinAppDriver will re-launch the application based on the initial information (capabilities) you provided during session creation. In the case of your version of Microsoft Excel configured the way it was, it simply highlighted existing instance instead of creating a new instance. As a result, the main window that is now displayed is set as the main window as it is the first valid main window at this point belonging to the process.Now that we have the right explanation of what happened, you can use it as a working workaround as long as you configured your Microsoft Excel the way it was. In fact this is a very good use of the
launchApp()in this particular condition. Alternatively, you can also useSwitchTo()API to switch to the right main window once the correct main window is displayed. Below is a sample on how to switch window if your session is pointing to a wrong window such as the splash screen:DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", YourAppId); WindowsDriver<WindowsElement> session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(session); // Identify the current window handle. You can check through inspect.exe which window this is. var currentWindowHandle = session.CurrentWindowHandle; // Wait for 5 seconds or however long it is needed for the right window to appear/for the splash screen to be dismissed Thread.Sleep(TimeSpan.FromSeconds(5)); // Return all window handles associated with this process/application. // At this point hopefully you have one to pick from. Otherwise you can // simply iterate through them to identify the one you want. var allWindowHandles = session.WindowHandles; // Assuming you only have only one window entry in allWindowHandles and it is in fact the correct one, // switch the session to that window as follows. You can repeat this logic with any top window with the same // process id (any entry of allWindowHandles) session.SwitchTo().Window(allWindowHandles[0]);For the benefit of others, below is the snippet of your workaround that will work if the application under test enforce single instance and will simply bring up already launched instance when being re-launched.
DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", YourAppId); WindowsDriver<WindowsElement> session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); Assert.IsNotNull(session); // Wait for 5 seconds or however long it is needed for the right window to appear/for the splash screen to be dismissed Thread.Sleep(TimeSpan.FromSeconds(5)); // When the application uses pre-launched existing instance, re-launching the application simply update // the current application window to whatever current main window belonging to the same application // process id session.LaunchApp();
Please, what would be the corresponding solution in Python code?
Creating a session with Appium-Python-Client immediatly throws me an exception, preventing me to apply any kind of sleepy or anything else.
Most helpful comment
Hi @vijay44,
The first error you encounter is due to the way Microsoft Excel launches. When Excel is not yet launched and you create a new session to launch it, Excel will start few processes and potentially show multiple windows like a splash screen. At this point, Windows Application Driver takes the first valid application window (the splash screen) and treat it as the main window to interact with. As soon as the splash screen is dismissed, any subsequent commands you send to it will result in no such window error which you saw.
When you wait enough time until the main window containing the Blank workbook is displayed and invoke
launchApp()API, WinAppDriver will re-launch the application based on the initial information (capabilities) you provided during session creation. In the case of your version of Microsoft Excel configured the way it was, it simply highlighted existing instance instead of creating a new instance. As a result, the main window that is now displayed is set as the main window as it is the first valid main window at this point belonging to the process.Now that we have the right explanation of what happened, you can use it as a working workaround as long as you configured your Microsoft Excel the way it was. In fact this is a very good use of the
launchApp()in this particular condition. Alternatively, you can also useSwitchTo()API to switch to the right main window once the correct main window is displayed. Below is a sample on how to switch window if your session is pointing to a wrong window such as the splash screen:```c# session = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appCapabilities);
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", YourAppId);
WindowsDriver
Assert.IsNotNull(session);
// Identify the current window handle. You can check through inspect.exe which window this is.
var currentWindowHandle = session.CurrentWindowHandle;
// Wait for 5 seconds or however long it is needed for the right window to appear/for the splash screen to be dismissed
Thread.Sleep(TimeSpan.FromSeconds(5));
// Return all window handles associated with this process/application.
// At this point hopefully you have one to pick from. Otherwise you can
// simply iterate through them to identify the one you want.
var allWindowHandles = session.WindowHandles;
// Assuming you only have only one window entry in allWindowHandles and it is in fact the correct one,
// switch the session to that window as follows. You can repeat this logic with any top window with the same
// process id (any entry of allWindowHandles)
session.SwitchTo().Window(allWindowHandles[0]);