Appium Java 平台如何拖拽元素?

Mr Wang · 2014年04月15日 · 最后由 Mr Wang 回复于 2014年04月15日 · 1731 次阅读

Java 平台如何拖拽元素?

利用 uiautomatorviewer.bat 看不到此元素的 相关信息 ,点击没反应

共收到 13 条回复 时间 点赞

已经更新截图

你可以在右图刷新一下界面,然后看看他的 UI 元素。

#2 楼 @michailclj UI 元素 看不到的

漂浮的图层貌似 uiautomatorviewer 的确看不到, 你看看 dump 的界面结构里面有没有这些元素, 尝试用 xpath 来定位下试试.

#4 楼 @seveniruby 恩 我试试 之后再说 多谢

#6 楼 @seveniruby 这个图是你说的 dump 结构吗?

我说的是命令行的 dump, 或者 appium 的那个 page_source

#8 楼 @seveniruby 求指导下 如何使用的,谢谢 没用过额

#9 楼 @young 在 adb 下使用 uiautomator 命令, 使用 dump 参数尝试 dump 页面结构, 这个你 google 下吧

#10 楼 @seveniruby OK 我会谷歌 的 ,刚才我是了下 用了 selenium webdriver 的一个方法:driver.getPageSource() 打出来的是这样的

{
  "hierarchy" : {
    "@rotation" : "1",
    "node" : {
      "@enabled" : "true",
      "@focusable" : "false",
      "@index" : "0",
      "@text" : "",
      "@checkable" : "false",
      "@package" : "com.example.android.contactmanager",
      "@scrollable" : "false",
      "@class" : "android.widget.FrameLayout",
      "@password" : "false",
      "@long-clickable" : "false",
      "@bounds" : "[0,0][1280,800]",
      "@selected" : "false",
      "@content-desc" : "",
      "@clickable" : "false",
      "@focused" : "false",
      "@checked" : "false",
      "node" : {
        "@enabled" : "true",
        "@focusable" : "false",
        "@index" : "0",
        "@text" : "",
        "@checkable" : "false",
        "@package" : "com.example.android.contactmanager",
        "@scrollable" : "false",
        "@class" : "android.widget.LinearLayout",
        "@password" : "false",
        "@long-clickable" : "false",
        "@bounds" : "[0,0][1280,800]",
        "@selected" : "false",
        "@content-desc" : "",
        "@clickable" : "false",
        "@focused" : "false",
        "@checked" : "false",
        "node" : [ {
          "@enabled" : "true",
          "@focusable" : "false",
          "@index" : "0",
          "@text" : "",
          "@checkable" : "false",
          "@package" : "com.example.android.contactmanager",
          "@scrollable" : "false",
          "@class" : "android.widget.FrameLayout",
          "@password" : "false",
          "@long-clickable" : "false",
          "@bounds" : "[0,33][1280,66]",
          "@selected" : "false",
          "@content-desc" : "",
          "@clickable" : "false",
          "@focused" : "false",
          "@checked" : "false",
          "node" : {
            "@enabled" : "true",
            "@focusable" : "false",
            "@index" : "0",
            "@text" : "Add Contact",
            "@checkable" : "false",
            "@package" : "com.example.android.contactmanager",
            "@scrollable" : "false",
            "@class" : "android.widget.TextView",
            "@password" : "false",
            "@long-clickable" : "false",
            "@bounds" : "[5,34][1275,64]",
            "@selected" : "false",
            "@content-desc" : "",
            "@clickable" : "false",
            "@focused" : "false",
            "@checked" : "false"
          }
        }, {
          "@enabled" : "true",
          "@focusable" : "false",
          "@index" : "1",
          "@text" : "",
          "@checkable" : "false",
          "@package" : "com.example.android.contactmanager",
          "@scrollable" : "false",
          "@class" : "android.widget.FrameLayout",
          "@password" : "false",
          "@long-clickable" : "false",
          "@bounds" : "[0,66][1280,800]",
          "@selected" : "false",
          "@content-desc" : "",
          "@clickable" : "false",
          "@focused" : "false",
          "@checked" : "false",
          "node" : {
            "@enabled" : "true",
            "@focusable" : "true",
            "@index" : "0",
            "@text" : "",
            "@checkable" : "false",
            "@package" : "com.example.android.contactmanager",
            "@scrollable" : "false",
            "@class" : "android.widget.ScrollView",
            "@password" : "false",
            "@long-clickable" : "false",
            "@bounds" : "[0,66][1280,800]",
            "@selected" : "false",
            "@content-desc" : "",
            "@clickable" : "false",
            "@focused" : "false",
            "@checked" : "false",
            "node" : {
              "@enabled" : "true",
              "@focusable" : "false",
              "@index" : "0",
              "@text" : "",
              "@checkable" : "false",
              "@package" : "com.example.android.contactmanager",
              "@scrollable" : "false",
              "@class" : "android.widget.TableLayout",
              "@password" : "false",
              "@long-clickable" : "false",
              "@bounds" : "[0,66][1280,497]",
              "@selected" : "false",
              "@content-desc" : "",
              "@clickable" : "false",
              "@focused" : "false",
              "@checked" : "false",
              "node" : [ {
                "@enabled" : "true",
                "@focusable" : "false",
                "@index" : "0",
                "@text" : "",
                "@checkable" : "false",
                "@package" : "com.example.android.contactmanager",
                "@scrollable" : "false",
                "@class" : "android.widget.TableRow",
                "@password" : "false",
                "@long-clickable" : "false",
                "@bounds" : "[0,66][1280,93]",
                "@selected" : "false",
                "@content-desc" : "",
                "@clickable" : "false",
                "@focused" : "false",
                "@checked" : "false",
                "node" : {
                  "@enabled" : "true",
                  "@focusable" : "false",
                  "@index" : "0",
                  "@text" : "Target Account",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "false",
                  "@class" : "android.widget.TextView",
                  "@password" : "false",
                  "@long-clickable" : "false",
                  "@bounds" : "[0,66][332,93]",
                  "@selected" : "false",
                  "@content-desc" : "Target Account",
                  "@clickable" : "false",
                  "@focused" : "false",
                  "@checked" : "false"
                }
              }, {
                "@enabled" : "true",
                "@focusable" : "false",
                "@index" : "1",
                "@text" : "",
                "@checkable" : "false",
                "@package" : "com.example.android.contactmanager",
                "@scrollable" : "false",
                "@class" : "android.widget.TableRow",
                "@password" : "false",
                "@long-clickable" : "false",
                "@bounds" : "[0,93][1280,158]",
                "@selected" : "false",
                "@content-desc" : "",
                "@clickable" : "false",
                "@focused" : "false",
                "@checked" : "false",
                "node" : {
                  "@enabled" : "true",
                  "@focusable" : "false",
                  "@index" : "0",
                  "@text" : "",
                  "@checkable" : "false",
                  "@scrollable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@class" : "android.widget.Spinner",
                  "@password" : "false",
                  "@long-clickable" : "false",
                  "@bounds" : "[0,93][1280,158]",
                  "@selected" : "false",
                  "@content-desc" : "",
                  "@NAF" : "true",
                  "@clickable" : "true",
                  "@focused" : "false",
                  "@checked" : "false"
                }
              }, {
                "@enabled" : "true",
                "@focusable" : "false",
                "@index" : "2",
                "@text" : "",
                "@checkable" : "false",
                "@package" : "com.example.android.contactmanager",
                "@scrollable" : "false",
                "@class" : "android.widget.TableRow",
                "@password" : "false",
                "@long-clickable" : "false",
                "@bounds" : "[0,158][1280,185]",
                "@selected" : "false",
                "@content-desc" : "",
                "@clickable" : "false",
                "@focused" : "false",
                "@checked" : "false",
                "node" : {
                  "@enabled" : "true",
                  "@focusable" : "false",
                  "@index" : "0",
                  "@text" : "Contact Name",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "false",
                  "@class" : "android.widget.TextView",
                  "@password" : "false",
                  "@long-clickable" : "false",
                  "@bounds" : "[0,158][332,185]",
                  "@selected" : "false",
                  "@content-desc" : "Contact Name",
                  "@clickable" : "false",
                  "@focused" : "false",
                  "@checked" : "false"
                }
              }, {
                "@enabled" : "true",
                "@focusable" : "false",
                "@index" : "3",
                "@text" : "",
                "@checkable" : "false",
                "@package" : "com.example.android.contactmanager",
                "@scrollable" : "false",
                "@class" : "android.widget.TableRow",
                "@password" : "false",
                "@long-clickable" : "false",
                "@bounds" : "[0,185][1280,249]",
                "@selected" : "false",
                "@content-desc" : "",
                "@clickable" : "false",
                "@focused" : "false",
                "@checked" : "false",
                "node" : {
                  "@enabled" : "true",
                  "@focusable" : "true",
                  "@index" : "0",
                  "@text" : "王 阳",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "false",
                  "@class" : "android.widget.EditText",
                  "@password" : "false",
                  "@long-clickable" : "true",
                  "@bounds" : "[0,185][1280,249]",
                  "@selected" : "false",
                  "@content-desc" : "",
                  "@clickable" : "true",
                  "@focused" : "false",
                  "@checked" : "false"
                }
              }, {
                "@enabled" : "true",
                "@focusable" : "false",
                "@index" : "4",
                "@text" : "",
                "@checkable" : "false",
                "@package" : "com.example.android.contactmanager",
                "@scrollable" : "false",
                "@class" : "android.widget.TableRow",
                "@password" : "false",
                "@long-clickable" : "false",
                "@bounds" : "[0,249][1280,276]",
                "@selected" : "false",
                "@content-desc" : "",
                "@clickable" : "false",
                "@focused" : "false",
                "@checked" : "false",
                "node" : {
                  "@enabled" : "true",
                  "@focusable" : "false",
                  "@index" : "0",
                  "@text" : "Contact Phone",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "false",
                  "@class" : "android.widget.TextView",
                  "@password" : "false",
                  "@long-clickable" : "false",
                  "@bounds" : "[0,249][332,276]",
                  "@selected" : "false",
                  "@content-desc" : "Contact Phone",
                  "@clickable" : "false",
                  "@focused" : "false",
                  "@checked" : "false"
                }
              }, {
                "@enabled" : "true",
                "@focusable" : "false",
                "@index" : "5",
                "@text" : "",
                "@checkable" : "false",
                "@package" : "com.example.android.contactmanager",
                "@scrollable" : "false",
                "@class" : "android.widget.TableRow",
                "@password" : "false",
                "@long-clickable" : "false",
                "@bounds" : "[0,276][1280,341]",
                "@selected" : "false",
                "@content-desc" : "",
                "@clickable" : "false",
                "@focused" : "false",
                "@checked" : "false",
                "node" : [ {
                  "@enabled" : "true",
                  "@focusable" : "true",
                  "@index" : "0",
                  "@text" : "18872573204",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "false",
                  "@class" : "android.widget.EditText",
                  "@password" : "false",
                  "@long-clickable" : "true",
                  "@bounds" : "[0,276][1158,340]",
                  "@selected" : "false",
                  "@content-desc" : "",
                  "@clickable" : "true",
                  "@focused" : "false",
                  "@checked" : "false"
                }, {
                  "@enabled" : "true",
                  "@focusable" : "true",
                  "@index" : "1",
                  "@text" : "",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "true",
                  "@class" : "android.widget.Spinner",
                  "@password" : "false",
                  "@long-clickable" : "false",
                  "@bounds" : "[1158,277][1280,342]",
                  "@selected" : "false",
                  "@content-desc" : "",
                  "@clickable" : "true",
                  "@focused" : "false",
                  "@checked" : "false",
                  "node" : {
                    "@enabled" : "true",
                    "@focusable" : "false",
                    "@index" : "0",
                    "@text" : "家庭",
                    "@checkable" : "false",
                    "@package" : "com.example.android.contactmanager",
                    "@scrollable" : "false",
                    "@class" : "android.widget.TextView",
                    "@password" : "false",
                    "@long-clickable" : "false",
                    "@bounds" : "[1172,292][1212,321]",
                    "@selected" : "false",
                    "@content-desc" : "",
                    "@clickable" : "false",
                    "@focused" : "false",
                    "@checked" : "false"
                  }
                } ]
              }, {
                "@enabled" : "true",
                "@focusable" : "false",
                "@index" : "6",
                "@text" : "",
                "@checkable" : "false",
                "@package" : "com.example.android.contactmanager",
                "@scrollable" : "false",
                "@class" : "android.widget.TableRow",
                "@password" : "false",
                "@long-clickable" : "false",
                "@bounds" : "[0,341][1280,368]",
                "@selected" : "false",
                "@content-desc" : "",
                "@clickable" : "false",
                "@focused" : "false",
                "@checked" : "false",
                "node" : {
                  "@enabled" : "true",
                  "@focusable" : "false",
                  "@index" : "0",
                  "@text" : "Contact Email",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "false",
                  "@class" : "android.widget.TextView",
                  "@password" : "false",
                  "@long-clickable" : "false",
                  "@bounds" : "[0,341][332,368]",
                  "@selected" : "false",
                  "@content-desc" : "Contact Email",
                  "@clickable" : "false",
                  "@focused" : "false",
                  "@checked" : "false"
                }
              }, {
                "@enabled" : "true",
                "@focusable" : "false",
                "@index" : "7",
                "@text" : "",
                "@checkable" : "false",
                "@package" : "com.example.android.contactmanager",
                "@scrollable" : "false",
                "@class" : "android.widget.TableRow",
                "@password" : "false",
                "@long-clickable" : "false",
                "@bounds" : "[0,368][1280,433]",
                "@selected" : "false",
                "@content-desc" : "",
                "@clickable" : "false",
                "@focused" : "false",
                "@checked" : "false",
                "node" : [ {
                  "@enabled" : "true",
                  "@focusable" : "true",
                  "@index" : "0",
                  "@text" : "stephenwang1011@gmail.com",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "false",
                  "@class" : "android.widget.EditText",
                  "@password" : "false",
                  "@long-clickable" : "true",
                  "@bounds" : "[0,368][1158,432]",
                  "@selected" : "false",
                  "@content-desc" : "",
                  "@clickable" : "true",
                  "@focused" : "true",
                  "@checked" : "false"
                }, {
                  "@enabled" : "true",
                  "@focusable" : "true",
                  "@index" : "1",
                  "@text" : "",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "true",
                  "@class" : "android.widget.Spinner",
                  "@password" : "false",
                  "@long-clickable" : "false",
                  "@bounds" : "[1158,369][1280,434]",
                  "@selected" : "false",
                  "@content-desc" : "",
                  "@clickable" : "true",
                  "@focused" : "false",
                  "@checked" : "false",
                  "node" : {
                    "@enabled" : "true",
                    "@focusable" : "false",
                    "@index" : "0",
                    "@text" : "家庭",
                    "@checkable" : "false",
                    "@package" : "com.example.android.contactmanager",
                    "@scrollable" : "false",
                    "@class" : "android.widget.TextView",
                    "@password" : "false",
                    "@long-clickable" : "false",
                    "@bounds" : "[1172,384][1212,413]",
                    "@selected" : "false",
                    "@content-desc" : "",
                    "@clickable" : "false",
                    "@focused" : "false",
                    "@checked" : "false"
                  }
                } ]
              }, {
                "@enabled" : "true",
                "@focusable" : "false",
                "@index" : "8",
                "@text" : "",
                "@checkable" : "false",
                "@package" : "com.example.android.contactmanager",
                "@scrollable" : "false",
                "@class" : "android.widget.TableRow",
                "@password" : "false",
                "@long-clickable" : "false",
                "@bounds" : "[0,433][1280,497]",
                "@selected" : "false",
                "@content-desc" : "",
                "@clickable" : "false",
                "@focused" : "false",
                "@checked" : "false",
                "node" : {
                  "@enabled" : "true",
                  "@focusable" : "true",
                  "@index" : "0",
                  "@text" : "Save",
                  "@checkable" : "false",
                  "@package" : "com.example.android.contactmanager",
                  "@scrollable" : "false",
                  "@class" : "android.widget.Button",
                  "@password" : "false",
                  "@long-clickable" : "false",
                  "@bounds" : "[0,433][1280,497]",
                  "@selected" : "false",
                  "@content-desc" : "Save",
                  "@clickable" : "true",
                  "@focused" : "false",
                  "@checked" : "false"
                }
              } ]
            }
          }
        } ]
      }
    }
  }
}

有点长,这个是我打印的 ContactManage.apk 的 pagesource

#12 楼 @young 你看看里面的元素有没有包含那个菜单项, 我看貌似有. 你就可以通过 xpath 直接定位了

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册