【问题标题】:How to find a WebView element in Android using Calabash using TextContent如何使用 TextContent 在 Android 中使用 Calabash 查找 WebView 元素
【发布时间】:2014-03-25 19:36:01
【问题描述】:

我在一个基本上没有 id 或类的 ios 应用程序中有一个 webview。 (我知道,对吧?) 但它确实有一个 textContent 字段,我想用它来选择元素。

This is the element I want to find:

{"rect"=>
   {"center_x"=>307.5,
    "left"=>295,
    "bottom"=>136,
    "right"=>320,
    "top"=>93,
    "width"=>25,
    "height"=>43,
    "center_y"=>178.5},
  "nodeName"=>"LI",
  "id"=>"",
  "textContent"=>"!!!   I WANT TO FIND IT BY THIS   !!!",
  "center"=>{"X"=>307.5, "Y"=>178.5},
  "nodeType"=>"ELEMENT_NODE",
  "webView"=>
   "<UIWebView: 0xe2e1400; frame = (0 0; 320 504); clipsToBounds = YES; autoresize = W+H
  "class"=>"arrow",
  "html"=>"<div class=\"arrow\"></div>"}

所以我能够使用 css 伪选择器找到这个

query("webView css:'el:first-child'")

我可以通过使用结果数组中的哈希来找到它 alá

query("webView css:'li'").select {|element| element["textContent"] == "!!!   I WANT TO FIND IT BY THIS   !!!}

我可以稍微重构一下以使用正则表达式 alá

query("webView css:'li'").select {|element| element["textContent"] =~ /I WANT/}

但这一切感觉真的很肮脏。非常非葫芦。有没有更好的方法来写这个?

【问题讨论】:

    标签: android css regex webview calabash


    【解决方案1】:

    我没有尝试过您的确切设置。但我确实经常在标签上使用带有 LIKE 比较的查询。 这能解决你的问题吗?

    例如。 element_exists("label {text LIKE '我想找到'}")

    【讨论】:

      【解决方案2】:

      我最终选择了这个:

      query("webView css:'TITLE'{textContent CONTAINS 'I WANT'}")

      它倾向于与这些特定的 webview 更一致地工作(鉴于代码中缺少可访问性标签)。

      【讨论】:

        猜你喜欢
        • 2014-05-07
        • 1970-01-01
        • 1970-01-01
        • 2018-11-19
        • 2016-06-30
        • 2021-06-07
        • 2014-10-27
        • 2020-02-12
        • 1970-01-01
        相关资源
        最近更新 更多