Couldn't click on "Blank workbook" button after launching MS Excel
See original GitHub issueHi,
I’m trying to do a sample workflow on Microsoft Excel 2016.
Workflow: 1.Launch MS Excel. 2. Click on “Blank workbook” to create a blank document. 3. Click on “Insert” tab.
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
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Excel opens a blank screen when you double-click a file ...
Offers resolutions to an issue where you see a blank screen when you try to open an Excel workbook by double-clicking its icon...
Read more >Repair a corrupted workbook
Recover data when you can't open the workbook in Excel ; Click File > New. ; Under New, click Blank workbook. ; Click...
Read more >Repairing a corrupted workbook
Click the arrow next to the Open button, and then click Open and Repair. Do one of the following: To recover as much...
Read more >Open Excel document but no worksheet is displayed.
To open Excel in application safe, click start > All Programs > Microsoft Office > Press and hold the Ctrl key and click...
Read more >Options won't open in files on Excel
1) Close all open Excel files. · 2) Go to `Start` and type `Excel` in the search box. · 3) Click on the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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: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.
Thanks @timotiusmargo. The above explanation is more helpful and interesting .