1

I want to define a WindowsElement so I can reuse it , but if I run it , it throws java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.windows.WindowsElement

I went though some WinAppDriver bugs ,but all were closed without any useful information.

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();

    }
Sameera De Silva
  • 1,722
  • 1
  • 22
  • 41

1 Answers1

0

Change the element type to a WebElement had solved my issue .

@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();

    }
Sameera De Silva
  • 1,722
  • 1
  • 22
  • 41