【问题标题】:WinAppDriver could not find element sometimesWinAppDriver 有时找不到元素
【发布时间】:2020-02-28 15:16:32
【问题描述】:

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 始终正确运行,但测试始终返回不同的结果。 为什么会这样?

【问题讨论】:

    标签: selenium winappdriver


    【解决方案1】:

    如果应用程序可能没有正确加载,可能会发生这种情况,请尝试添加显式等待。

    【讨论】:

      猜你喜欢
      • 2018-08-28
      • 2020-02-13
      • 2019-12-07
      • 2020-08-11
      • 2018-02-10
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      • 2020-04-19
      相关资源
      最近更新 更多