WinAppDriver如何在Java中定义WindowsElement而不获取Java.lang.ClassCastException

WinAppDriver如何在Java中定义WindowsElement而不获取Java.lang.ClassCastException,java,winappdriver,Java,Winappdriver,我想定义一个WindowsElement以便可以重用它,但如果我运行它,它会抛出java.lang.ClassCastException:org.openqa.selenium.remote.RemoteWebElement无法强制转换为io.appium.java_client.windows.WindowsElement 我检查了一些WinAppDriver错误,但所有错误都被关闭,没有任何有用的信息 public class WinAppDriverWaitsExample {

我想定义一个WindowsElement以便可以重用它,但如果我运行它,它会抛出java.lang.ClassCastException:org.openqa.selenium.remote.RemoteWebElement无法强制转换为io.appium.java_client.windows.WindowsElement

我检查了一些WinAppDriver错误,但所有错误都被关闭,没有任何有用的信息

public class WinAppDriverWaitsExample {

    private static WindowsDriver<WebElement> driver = null;
    private static WebElement alarm = null;

    @BeforeClass
    public static void setup() {
        try {       
            DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("app", "Microsoft.WindowsAlarms_8wekyb3d8bbwe!App");             

            driver = new WindowsDriver<WebElement>(new URL("http://127.0.0.1:4723"), capabilities);
            driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);

            //To make sure app is launched
            alarm = driver.findElementByName("Alarm tab");
            Assert.assertNotNull(alarm);

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

    @Test
    public void timer() {
        System.out.println("Start and stop the alarm clock");
        //It is AutomationID
         driver.findElementByAccessibilityId("TimerPivotItem").click();
        WindowsElement  startBtn= (WindowsElement) driver.findElementByName("Start");
         WindowsElement  pasueBtn=(WindowsElement) driver.findElementByName("Pause");
         startBtn.click();
         pasueBtn.click();

    }
公共类WinAppDriverWaitsExample{
私有静态WindowsDriver驱动程序=null;
私有静态WebElement报警=null;
@课前
公共静态无效设置(){
试试{
DesiredCapabilities=新的DesiredCapabilities();
capabilities.setCapability(“应用程序”、“Microsoft.WindowsAlarms_8wekyb3d8bbwe!应用程序”);
驱动程序=新Windows驱动程序(新URL(“http://127.0.0.1:4723(能力),;
driver.manage().timeouts().implicitlyWait(12,TimeUnit.SECONDS);
//确保应用程序已启动
报警=driver.findElementByName(“报警选项卡”);
Assert.assertNotNull(报警);
}捕获(例外e){
e、 printStackTrace();
}最后{
}
}
@试验
公共无效计时器(){
System.out.println(“启动和停止闹钟”);
//它是自动的
driver.findElementByAccessibilityId(“TimerPivotItem”)。单击();
WindowsElement startBtn=(WindowsElement)驱动程序。findElementByName(“开始”);
WindowsElement pasueBtn=(WindowsElement)driver.findElementByName(“暂停”);
startBtn.click();
pasueBtn.click();
}

将元素类型更改为WebElement已解决我的问题

@Test
    public void timer() {
        System.out.println("Start and stop the alarm clock");
        //It is AutomationID
         driver.findElementByAccessibilityId("TimerPivotItem").click();
         WebElement  startBtn= driver.findElementByName("Start");
         WebElement  pasueBtn=driver.findElementByName("Pause");
         startBtn.click();
         pasueBtn.click();

    }

将元素类型更改为WebElement已解决我的问题

@Test
    public void timer() {
        System.out.println("Start and stop the alarm clock");
        //It is AutomationID
         driver.findElementByAccessibilityId("TimerPivotItem").click();
         WebElement  startBtn= driver.findElementByName("Start");
         WebElement  pasueBtn=driver.findElementByName("Pause");
         startBtn.click();
         pasueBtn.click();

    }