【发布时间】: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