其他分享
首页 > 其他分享> > 如何在calabash-ios / calabash-android中找到相关的WebView元素

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

作者:互联网

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

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

解决方法:

你可以使用xpath找到它:

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

要么

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\"]'")

标签:css,android,ios,webview,calabash
来源: https://codeday.me/bug/20190624/1279437.html