【问题标题】:How to get WebView details information by calabash-android?calabash-android如何获取WebView的详细信息?
【发布时间】:2016-08-13 00:02:27
【问题描述】:

我打算使用 calabash-android 开发 android app 的自动化测试脚本。 但我不知道如何触摸/查询以下页面中的“注册”按钮:

我尝试在 calabash 控制台中“查询“*”,但无法获得有关 按钮。查询输出:

    irb(main):002:0> query "*"
[
    [0] {
                        "id" => nil,
                   "enabled" => true,
        "contentDescription" => nil,
                   "visible" => true,
                       "tag" => nil,
               "description" => "com.android.internal.policy.impl.PhoneWindow$De
corView{b11eeb10 V.E..... R.....I. 0,0-768,1134}",
                     "class" => "com.android.internal.policy.impl.PhoneWindow$De
corView",
                      "rect" => {
            "center_y" => 617,
            "center_x" => 384,
              "height" => 1134,
                   "y" => 50,
               "width" => 768,
                   "x" => 0
        }
    },
    [1] {
                        "id" => nil,
                   "enabled" => true,
        "contentDescription" => nil,
                   "visible" => true,
                       "tag" => nil,
               "description" => "android.widget.LinearLayout{b10779d0 V.E..... .
.....I. 0,0-768,1134}",
                     "class" => "android.widget.LinearLayout",
                      "rect" => {
            "center_y" => 617,
            "center_x" => 384,
              "height" => 1134,
                   "y" => 50,
               "width" => 768,
                   "x" => 0
        }
    },
    [2] {
                        "id" => "content",
                   "enabled" => true,
        "contentDescription" => nil,
                   "visible" => true,
                       "tag" => nil,
               "description" => "android.widget.FrameLayout{b1234b00 V.E..... ..
....I. 0,0-768,1134 #1020002 android:id/content}",
                     "class" => "android.widget.FrameLayout",
                      "rect" => {
            "center_y" => 617,
            "center_x" => 384,
              "height" => 1134,
                   "y" => 50,
               "width" => 768,
                   "x" => 0
        }
    },
    [3] {
                        "id" => nil,
                   "enabled" => true,
        "contentDescription" => nil,
                   "visible" => true,
                       "tag" => nil,
               "description" => "android.widget.LinearLayout{b11ecf40 V.E..... .
.....I. 0,0-768,1134}",
                     "class" => "android.widget.LinearLayout",
                      "rect" => {
            "center_y" => 617,
            "center_x" => 384,
              "height" => 1134,
                   "y" => 50,
               "width" => 768,
                   "x" => 0
        }
    },
    [4] {
                        "id" => "NoResourceEntry-6",
                   "enabled" => true,
        "contentDescription" => "Web View",
                   "visible" => true,
                       "tag" => nil,
               "description" => "org.apache.cordova.inappbrowser.InAppBrowser$6$
5{b108af68 VFEDHVC. .F....I. 0,0-768,1134 #6}",
                     "class" => "org.apache.cordova.inappbrowser.InAppBrowser$6$
5",
                      "rect" => {
            "center_y" => 617,
            "center_x" => 384,
              "height" => 1134,
                   "y" => 50,
               "width" => 768,
                   "x" => 0
        }
    }
]

你能给我一些建议吗?非常感谢!

【问题讨论】:

  • 你的应用:是原生的还是混合的?

标签: calabash calabash-android


【解决方案1】:

我将回答这个问题,认为您的应用是一个混合应用。我不确定这是否适用于本机应用程序。我对此表示怀疑。
如果您想获取有关 DOM 中所有元素的一些信息,您应该使用以下说明:

query("systemWebview css:'*'")

该指令将返回一个包含 Web 视图中所有元素的数组。您将获得类、ID 等。如果您只想获得 textContent 包含单词 Register 的元素(这将帮助您更轻松地找到它),您应该运行以下命令:

query("systemWebview css:'*' {textContent CONTAINS 'Register'}")

检查结果并告诉我:这是你想要的吗?

【讨论】:

  • 我在 calabash-android 控制台中检查了两个命令,但没有任何返回。只需清空 []
  • 好吧。 Firstable,你确定它是一个混合应用程序吗?否则,您的应用将不会显示任何 web 视图。
  • 如何确认此应用类型?我是这些东西的新手。
  • 这个返回怎么样,那不是webview? "id" => "NoResourceEntry-6", "enabled" => true, "contentDescription" => "Web View", "visible" => true, "tag" => nil, "description" => "org. apache.cordova.inappbrowser.InAppBrowser$6$ 5{b108af68 VFEDHVC..F....I. 0,0-768,1134 #6}", "class" => "org.apache.cordova.inappbrowser.InAppBrowser$6 $ 5",
  • 对于第一条评论:如果您使用 ionic 或 cordova 等工具开发应用程序,那么它就是混合的。您也可以将您的设备插入您的 PC,转到 chrome://inspect,在您的手机上打开该应用程序并进行检查。检查元素选项卡,如果它具有网页的外观,那么它是混合的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-25
  • 2021-07-27
  • 1970-01-01
  • 2016-09-24
  • 1970-01-01
  • 1970-01-01
  • 2017-09-24
相关资源
最近更新 更多