iframe中的Android Espresso WebView访问元素



这次我尝试使用浓缩咖啡来测试我的应用。我使用WebView打开URL并在HTML代码下检查我面临一个问题,即我可以在iframe中访问元素。

<html>
  <head></head>
  <body>
    <iframe id="mainFrame" src="Address/Default.aspx" scrolling="no" 
    style="border: 0px; width: 100%; height: 432px; position: absolute;">
      <html>
        <head></head>
        <body>
          <button onclick = "one function">
        </body>
      </html>
    </iframe>
  </body>
</html>

我复制xpth是/html/html/body/button and code

onWebView().withElement(findElement(Locator.XPATH, "/html/body/button")).perform(webClick());

但是,我得到 atom评估返回null!,我无法获得元素。浓缩咖啡可以在iframe内部获取元素吗?我可以将元素不在iframe中。

当按钮在iframe内部时,我们需要使用.inWindow(selectFrameByIdOrName("mainFrame"))

onWebView()
    .inWindow(selectFrameByIdOrName("mainFrame"))
    .withElement(findElement(Locator.XPATH, "/html/body/button")).perform(webClick());

希望会有所帮助。

最新更新