microsoft / WinAppDriver

Windows Application Driver
MIT License
3.69k stars 1.4k forks source link

Failed to located opened application window with app id C:\Windows\System32\cmd.exe and Process Id:22300 #1614

Open rabia08 opened 3 years ago

rabia08 commented 3 years ago

Hi, I want to open a command prompt and apply some operations but the win app driver shows me this error. I am using Eclipse 2021-09. I apply all solutions but this error comes again and again. my code: package WinAppDriver.WinAppDriver;

import java.io.IOException; import java.net.MalformedURLException; import java.net.URL;

//import org.openqa.selenium.By; //import org.openqa.selenium.Keys; import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.windows.WindowsDriver; import io.appium.java_client.windows.WindowsElement;

public class Randm {

public static void main(String[] args) throws InterruptedException, IOException {

    DesiredCapabilities cap = new DesiredCapabilities();

    cap.setCapability("app", "C:\\Windows\\system32\\cmd.exe");

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

    cap.setCapability("appArguments", "/c SCHTASKS.EXE /RUN /TN \\\\iVMSTASK\\\\ivmsopen");
    //driver.findElement(By.name("Text Area")).sendKeys("SCHTASKS.EXE /RUN /TN \\iVMSTASK\\ivmsopen");
    //driver.getKeyboard().sendKeys(Keys.ENTER);

    Thread.sleep(15000);

    driver.quit();

}

}

Tree55Topz commented 3 years ago

@rabia08 can you explain what is happening, does the app even launch? Is this an intermittent issue?

Also, why are you using WinAppDriver to interact with cmd line? You could execute "SCHTASKS.EXE /RUN /TN \iVMSTASK\ivmsopen" programmatically without having to even use WinAppDriver. Just create a batch file and execute in code. See an example like this (C#) https://stackoverflow.com/questions/5519328/executing-batch-file-in-c-sharp

LisaAga commented 2 years ago

@Tree55Topz @anunay1 : Can you please update us here . I am facing similiar issue

LisaAga commented 2 years ago

@rabia08 : were you able to solve this?

Shakevg commented 2 years ago

@LisaAga As @Tree55Topz mentioned WinAppDriver is not the right tool for such cases, do it programmatically.