如何在calabash-ios和calabash-android中找到相关的WebView元素。我知道两者之间的语法略有不同,但问题是一样的。这是一个例子:
1) This query is too broad:
query("webView css:'div'")
# Returns all the div elements visible
2) I can find the div I need with:
query("webView css:'div'").find { |x| x["textContent"] =~ /text from my div/ }
# Returns the div element I'm looking for
3) and I can find all the button elements
query("webView css:'.button')
# Returns all the visible elements with .button class
4) and I can find all the buttons that are in a div
query("webView css:'div > .button'")
# Returns all the visible button elements that are children of a div
我无法做的是找到一个按钮,它是我在示例2
中找到的div的子项。
What I've tried:
pseudo-selectors don't work.
query("webView css:'div:first'")
# Returns an empty array
a combination of inheritance and class didn't work.
query("webView css:'div.classy-class > .button'")
# Returns an empty array
我疯了。我怎么能找到这个?
答案 0 :(得分:4)
您可以使用xpath找到它:
query("WebView xpath:'//div[text()=\"text from div\"]/*[@class=\"button\"]'")
OR
query("WebView xpath:'//div[contains(text(),\"text from div\")]/*[@class=\"button\"]'")
第二是通过部分文本找到div。上面的xpath只找到div的直接子节点。如果您需要查找此div中的所有按钮,请使用以下命令:
query("WebView xpath:'//div[text()=\"text from div\"]//*[@class=\"button\"]'")