我想定义一个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();
}
最佳答案
将元素类型更改为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/