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总是正确运行,但测试总是返回不同的结果。为什么会发生这种情况?
发布于 2020-02-28 15:16:32
如果此时应用程序可能未正确加载,则可能会发生这种情况,请尝试添加显式等待。
https://stackoverflow.com/questions/60435944
复制相似问题