如何在calabash-ios/calabash-android中找到相关的WebView元素

Joe*_*ick 4 css android webview ios calabash

如何在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
Run Code Online (Sandbox Code Playgroud)

我不能做的是找到一个按钮,它是我在 example 中找到的 div 的子级2。

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
Run Code Online (Sandbox Code Playgroud)

我要疯了。我怎样才能找到这个?

Iev*_*gen 5

您可以使用 xpath 找到它:

query("WebView xpath:'//div[text()=\"text from div\"]/*[@class=\"button\"]'")
Run Code Online (Sandbox Code Playgroud)

或者

query("WebView xpath:'//div[contains(text(),\"text from div\")]/*[@class=\"button\"]'") 
Run Code Online (Sandbox Code Playgroud)

第二是通过部分文本查找 div。上面的 xpath 只找到作为 div 的直接子级的按钮。如果您需要查找此 div 中的所有按钮,请使用以下命令:

query("WebView xpath:'//div[text()=\"text from div\"]//*[@class=\"button\"]'")
Run Code Online (Sandbox Code Playgroud)