WinAppDriver有时找到元素,有时找不到...我试图记录我的元素列表大小,而当我运行测试时,有时返回1,有时为0。我的代码:
public class Test {
public WindowsDriver<RemoteWebElement > driver;
@Before
public void setup() {
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("app", "C:\\Program Files\\App\\Bin\\MainFrame.exe");
capabilities.setCapability("platformName", "Windows");
capabilities.setCapability("deviceName", "WindowsPC");
driver = new WindowsDriver<RemoteWebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
}catch(Exception e){
e.printStackTrace();
} finally {
}
}
@Test
public void listLength() {
System.out.println(driver.findElementsByClassName("MaskEdit").size());
}
}
在日志中,我看到NoSuchElementException:
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.04 seconds
应用程序MainFrame.exe始终正确运行,但测试始终返回不同的结果。 为什么会这样?
答案 0 :(得分:0)
如果应用程序可能无法正确加载,则可能会发生这种情况,请尝试添加显式等待。