WinAppDriver OutLook New Email Elements not found

917 Views Asked by At

Trying to mimic (automate) email sending through outlook using WinAppDriver, the "New E-mail" element is recognized and new window opens but on the new Window the "To","CC" etc controls are not recognized.

I suspect the new windows session is not available for the driver.

try {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setPlatform(Platform.WIN10);
    //capabilities.setCapability("appTopLevelWindow", "0xBB880A");
    capabilities.setCapability("app", "C:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.exe");
        outlookSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities);
            outlookSession.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        newEmail = outlookSession.findElementByName("New E-mail");
        System.out.println("newEmail:::::: " + newEmail);
        newEmail.click();

        outlookSession.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        outlookSession.findElementByName("To").sendKeys("<email>"); (the 'To' element is not recognized.
3

There are 3 best solutions below

0
On BEST ANSWER

I think that the problem you are facing is cause by the fact that Outlook will create a new Windows for your new email. That will result in the window not being part of your current session. The best way to address this, is probably creating a desktop session, finding your new window and then attaching a new session and then controlling your new window from there.

Hope this helps.

~Gilles

0
On

You have to write the code for switching the window from outlook to New email.

            Thread.Sleep(TimeSpan.FromSeconds(5));
            var allWindowHandles1 = driver.WindowHandles;
            driver.SwitchTo().Window(allWindowHandles1[0]);

When ever you have new window then you have to switch the control from one window to other.

0
On

switchTo().activeElement() didn't work for me so I had to create a new session to interact with the elements on the new email page. Hopefully, this helps others who had the same issue as me

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("app", "Root");
    driver = new WindowsDriver<>(new URL("http://127.0.0.1:4723"), capabilities);