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

时间:2022-02-25 22:35:25

How can you find relative WebView elements in calabash-ios and calabash-android. I know the syntax is slightly different between the two but the issue is same. Here's an example:

如何在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

What I can't do is find a button that is a child of the div I found in example 2.

我不能做的是找到一个按钮,它是我在示例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

I'm going crazy. How can I find this?

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

1 个解决方案

#1


4  

You can find it using xpath:

可以使用xpath找到它:

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

OR

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

2nd is to find div by part of its text. The xpath above finds only buttons which are direct children of the div. If you need to find all buttons in this div use the following:

第二步是按部分文本查找div。上面的xpath只找到div的直接子按钮。

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

#1


4  

You can find it using xpath:

可以使用xpath找到它:

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

OR

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

2nd is to find div by part of its text. The xpath above finds only buttons which are direct children of the div. If you need to find all buttons in this div use the following:

第二步是按部分文本查找div。上面的xpath只找到div的直接子按钮。

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