【问题标题】:how to use result of query(*) to identify textbox and button ,and use performAction and touch to input text and click button如何使用查询结果(*)来识别文本框和按钮,并使用 performAction 和 touch 输入文本并单击按钮
【发布时间】:2026-02-16 12:05:01
【问题描述】:

我已经找到了所有主题,但没有找到与我的问题相关的任何答案。

我测试了一个 webview apk。 我打开一个 url("http://m.youdao.com/") 并想在编辑框中输入文本并单击研究按钮。

按钮没有id和名称,请查看网页的HTML。

现在 query(*) 可以工作并输出很多东西,但问题是哪一项与文本框相关,哪一项与按钮相关。我想在文本框中输入“测试”并点击搜索按钮。

查询结果: irb(main):006:0> 查询“*” [ [0]{ “id” => 无, “启用” => 真, “内容描述” => 无, "类" => "com.android.internal.policy.impl.PhoneWindow$DecorView", “矩形” => { "center_y" => 142.0, "center_x" => 120.0, “身高”=> 284, "y" => 0, “宽度” => 240, “x” => 0 }, “描述”=>“com.android.internal.policy.impl.PhoneWindow$DecorView{b2da1390 V.E.....R.....I. 0,0-240,284}” }, [1]{ "id" => "action_bar_overlay_layout", “启用” => 真, “内容描述” => 无, "类" => "com.android.internal.widget.ActionBarOverlayLayout", “矩形” => { "center_y" => 142.0, "center_x" => 120.0, “身高”=> 284, "y" => 0, “宽度” => 240, “x” => 0 }, “描述”=>“com.android.internal.widget.ActionBarOverlayLayout{b2dfed00 V.ED..........I. 0,0-240,284 #1020313 android:id/action_bar_overlay_layout}” }, [2]{ "id" => "内容", “启用” => 真, “内容描述” => 无, "类" => "android.widget.FrameLayout", “矩形” => { "center_y" => 169.5, "center_x" => 120.0, “身高”=> 229, "y" => 55, “宽度” => 240, “x” => 0 }, “描述”=>“android.widget.FrameLayout{b2da5930 V.E...........I. 0,55-240,284 #1020002 android:id/content}” }, [ 3] { "id" => "容器", “启用” => 真, “内容描述” => 无, "类" => "android.widget.FrameLayout", “矩形” => { "center_y" => 169.5, "center_x" => 120.0, “身高”=> 229, "y" => 55, “宽度” => 240, “x” => 0 }, “描述”=>“android.widget.FrameLayout{b2df76d0 V.E...........I. 0,0-240,229 #7f05003c app:id/container}” }, [4] { “id” => 无, “启用” => 真, “内容描述” => 无, "类" => "android.support.v4.app.NoSaveStateFrameLayout", “矩形” => { "center_y" => 169.5, "center_x" => 120.0, “身高”=> 229, "y" => 55, “宽度” => 240, “x” => 0 }, “描述”=>“android.support.v4.app.NoSaveStateFrameLayout{b2e2c3b8 V.E...........I. 0,0-240,229}” }, [5]{ “id” => 无, “启用” => 真, “内容描述” => 无, "类" => "android.widget.LinearLayout", “矩形” => { "center_y" => 169.5, "center_x" => 120.0, “身高”=> 229, "y" => 55, “宽度” => 240, “x” => 0 }, “描述”=>“android.widget.LinearLayout{b2df86d8 V.E...........I. 0,0-240,229}” }, [6]{ "id" => "mywebview", “启用” => 真, "contentDescription" => "网页视图", "类" => "android.webkit.WebView", “矩形” => { "center_y" => 169.5, "center_x" => 120.0, “身高”=> 229, "y" => 55, “宽度” => 240, “x” => 0 }, “描述”=>“android.webkit.WebView{b2dbdd18 VFEDHVC..F....I.0,0-240,229 #7f05003d app:id/mywebview}” }, [7]{ "id" => "action_bar_container", “启用” => 真, “内容描述” => 无, "类" => "com.android.internal.widget.ActionBarContainer", “矩形” => { "center_y" => 37.0, "center_x" => 120.0, “身高”=> 36, "y" => 19, “宽度” => 240, “x” => 0 }, “描述”=>“com.android.internal.widget.ActionBarContainer{b2dab088 V.ED..........I. 0,19-240,55 #1020314 android:id/action_bar_container}” }, [8]{ "id" => "action_bar", “启用” => 真, “内容描述” => 无, "类" => "com.android.internal.widget.ActionBarView", “矩形” => { "center_y" => 37.0, "center_x" => 120.0, “身高”=> 36, "y" => 19, “宽度” => 240, “x” => 0 }, “描述”=>“com.android.internal.widget.ActionBarView{b2d98560 V.E...........I. 0,0-240,36 #1020315 android:id/action_bar}” }, [ 9] { “id” => 无, “启用” => 假, “内容描述” => 无, "类" => "android.widget.LinearLayout", “矩形” => { "center_y" => 37.0, "center_x" => 66.5, “身高”=> 36, "y" => 19, “宽度” => 119, "x" => 7 }, “描述”=>“android.widget.LinearLayout{b2dab638 V.....C.......I. 7,0-126,36}” }, [10] { “id” => 无, “启用” => 真, “内容描述” => 无, "类" => "com.android.internal.widget.ActionBarView$HomeView", “矩形” => { "center_y" => 37.0, "center_x" => 22.0, “身高”=> 36, "y" => 19, “宽度” => 30, "x" => 7 }, “描述”=>“com.android.internal.widget.ActionBarView$HomeView{b2de3f00 V.E...........I. 0,0-30,36}” }, [11] { "id" => "家", “启用” => 真, “内容描述” => 无, "类" => "android.widget.ImageView", “矩形” => { "center_y" => 37.0, "center_x" => 22.0, “身高”=> 24, "y" => 25, “宽度” => 24, "x" => 10 }, “描述”=>“android.widget.ImageView{b2e14210 V.ED..........I. 3,6-27,30 #102002c android:id/home}” }, [12] { “id” => 无, “启用” => 真, “内容描述” => 无, "类" => "android.widget.LinearLayout", “矩形” => { "center_y" => 36.5, "center_x" => 81.5, “身高”=> 19, "y" => 27, “宽度” => 89, “x” => 37 }, “描述”=>“android.widget.LinearLayout{b2dda508 V.E...........I. 30,8-119,27}” }, [13] { "id" => "action_bar_title", “启用” => 真, “内容描述” => 无, "类" => "android.widget.TextView", "文本" => "TestWebView", “矩形” => { "center_y" => 36.5, "center_x" => 78.5, “身高”=> 19, "y" => 27, “宽度” => 83, “x” => 37 }, “描述”=>“android.widget.TextView{b2dbc4b8 V.ED..........I. 0,0-83,19 #1020265 android:id/action_bar_title}” }, [14] { “id” => 无, “启用” => 真, “内容描述” => 无, "类" => "com.android.internal.view.menu.ActionMenuView", “矩形” => { "center_y" => 37.0, "center_x" => 219.0, “身高”=> 36, "y" => 19, “宽度” => 42, “x” => 198 }, “描述”=>“com.android.internal.view.menu.ActionMenuView{b2df5188 V.ED..........I. 198,0-240,36}” }, [15] { “id” => 无, “启用” => 真, "contentDescription" => "更多选项", "类" => "com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton", “矩形” => { "center_y" => 37.0, "center_x" => 219.0, “身高”=> 36, "y" => 19, “宽度” => 42, “x” => 198 }, “描述”=>“com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton{b2de1788 VFED..C.......I. 0,0-42,36}” } ] 这是我的功能和步骤定义。
功能:WebView 功能

  Scenario: Test WebView

    Then I wait for 10 seconds

    Then I take a picture

    Then I enter "test" into input field with id "formInput" 

    Then I wait for 100 seconds

    Then I take a picture

    Then I press the button with id "input[class='btn']" // here i don't know use which property of the button to identify it ???

    Then I wait for 100 seconds

    Then I take a picture

Step definition is as bellow :
Then /^I enter "([^\"]*)" into input field with id "([^\"]*)"$/ do |text, css|


      performAction("set_text","WebView css:'input[text=\"TestWebView\"]'",text)



end



Then /^I press the button with id "([^\"]*)"$/ do |css|

      touch ("webView css:'input[contentDescription=\"More options\"]'")
end



Then /^I touch the button with id "([^\"]*)"$/ do | css|

  performAction('touch','css',css)

end



Then /^show the html source code$/ do

  performAction('dump_body_html')

end

【问题讨论】:

    标签: calabash


    【解决方案1】:
    1. 执行calabash-android console path_to/your_app.apk;

    2. 然后执行reinstall_apps,然后是start_test_server_in_background,然后是query "*"

    【讨论】:

    • 按照你的方式工作,我的问题是如何使用我的测试应用程序让查询输出一些东西?
    • 另一个,我记得我已经接受了电子邮件通知,但是当你回答我的问题时为什么没有电子邮件发送给我。所以我很抱歉稍后回复。
    • 当我输入:calabash-android run testWebView.apk -v,结果是:"bonusInformation":[],"message":"",""success": true
    • 我有多个问题,感谢您的耐心。而且,第一个问题是:从查询结果中,我想知道应该使用哪个标签或标签或项目来查找文本框和按钮。结果与 HTML 不同,从 HTML 中,我看到文本框的名称是 "q" ,但我无法从查询结果中找到 "q"*;从 html 中,该按钮仅具有类属性“btn”,并且我也无法从查询结果中找到 btn。所以我不知道为什么很多人使用查询来帮助他们,它的用途是什么?
    • Dmitry ,以下这两种方法都可以正常工作。 performAction("set_text",'css','input[name=q]', text); performAction("set_text",'webView css','input[name=q]', text) .