我想定义一个 WindowsElement,以便可以重用它,但如果运行它,它会抛出 java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement 无法转换为 io.appium.java_client.windows。 Windows元素
我发现了一些 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();
}
最佳答案
将元素类型更改为 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();
}
关于java - WinAppDriver 如何在 Java 中定义 WindowsElement 而不会出现 java.lang.ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60351727/