1

I am importing Appium (java-client-7.3.0.jar) and Selenium library for my project. My function:

import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By.ByClassName;
import org.openqa.selenium.By.ByName;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.net.URL;

import io.appium.java_client.android.nativekey.KeyEvent;
import io.appium.java_client.windows.WindowsDriver;
import io.appium.java_client.windows.WindowsElement;

import java.awt.RenderingHints.Key;
import java.awt.Robot;
import java.lang.reflect.Array;

public class WinAppEmail {
    private static WindowsDriver<WindowsElement> session = null;

     public void setup() {
            try {
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.setCapability("app", "C:\\Program Files\\Microsoft Office\\Office16\\OUTLOOK.EXE");

                session = new WindowsDriver<WindowsElement>(new URL("http://127.0.0.1:4723"), capabilities);

                session.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

                String strCurrentWindow="" ; 
//              strCurrentWindow = session.getWindowHandle();  // => Can't not get current handle

//              Robot robot = new Robot();
//              robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL);
//              robot.keyPress(java.awt.event.KeyEvent.VK_N);
//              robot.keyRelease(java.awt.event.KeyEvent.VK_N);
//              robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL);

                session.findElementByName("New Email").click(); // => Can't find 


            }catch(Exception e){
                e.printStackTrace();
            } finally {
            }
        }
}

My code have 2 issue. 1. It can't get current window handle (strCurrentWindow = session.getWindowHandle();) 2. It can't click button on Outlook mail(session.findElementByName("New Email").click();) Please, help me! thanks all.

exception: Feb 07, 2020 3:55:42 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0 INFO: Detected dialect: OSS --------------- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils at io.appium.java_client.internal.ElementMap.getElementClass(ElementMap.java:77) at io.appium.java_client.internal.JsonToMobileElementConverter.newRemoteWebElement(JsonToMobileElementConverter.java:67) at io.appium.java_client.internal.JsonToMobileElementConverter.apply(JsonToMobileElementConverter.java:57) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:561) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.windows.WindowsDriver.execute(WindowsDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323) at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61) at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1) at io.appium.java_client.windows.WindowsDriver.findElement(WindowsDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:404) at io.appium.java_client.DefaultGenericMobileDriver.findElementByName(DefaultGenericMobileDriver.java:117) at io.appium.java_client.AppiumDriver.findElementByName(AppiumDriver.java:1) at io.appium.java_client.windows.WindowsDriver.findElementByName(WindowsDriver.java:1) at Allegro.WinAppEmail.setup(WinAppEmail.java:59) at Allegro.MainFunction.main(MainFunction.java:9) Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 17 more

Suryakant Bharti
  • 673
  • 1
  • 6
  • 24
denis bui
  • 65
  • 7

1 Answers1

1

are you able to open Outlook? if no , then try changing the path for the same to :

C:/Program Files (x86)/Microsoft Office/root/Office16/OUTLOOK.EXE

I was able to do both the thing i.e. getting the windowHanlde as well as clicking on new mail , using this path.

  • I can open Outlook but not click on "New Email" button. I was try to your xpath but I can't use it. – denis bui Feb 11 '20 at 03:59
  • The path mentioned is not the locator (i.e. xpath of 'New Email' button) instead it is the path of the Outlook application that we mentioned while setting the capability. capabilities.setCapability("app", "C:/Program Files (x86)/Microsoft Office/root/Office16/OUTLOOK.EXE"); You can locate the 'New Email' element by : driver.findElementByName("New Email").click(); – Sukhangad singh Feb 11 '20 at 05:38
  • I spoke above is in my PC your xpath not run. After change from my xpath to your xpath, outlook application can not open. I think your OS 32 bit, I use OS 64 bit – denis bui Feb 11 '20 at 06:32
  • I am also having 64 bit , there is one more way to open outlook without giving the whole path just : capabilities.setCapability("app", "OUTLOOK.EXE"); This will open the app and you can try to click on new email. – Sukhangad singh Feb 11 '20 at 07:07
  • sorry, I can't click it. you can show your example that you used – denis bui Feb 11 '20 at 09:52
  • DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("app", "OUTLOOK.EXE"); driver = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); String h = driver.getWindowHandle(); driver.findElementByName("New Email").click(); – Sukhangad singh Feb 13 '20 at 08:32