Filtering an element using its property in arrays – calabash

Hello again,

More one tip about filtering the element in an array, using some of the properties that you want (text content, position, id, class, html, etc…). In this example, I am finding the array of elements with the specific CSS and after I am returning the element where the property “TextContent” equals a Login.

menu = query("WebView index:0 css:'div li span'").find { |x|
x["textContent"] == "Login" }

Or:

menu = query("WebView index:0 css:'div li span'", :textContent).find { |x| 
x == "Login" }

In this other example, I am returning the element which contains specific text inside of the property “html“.

menu_figure = query("WebView index:0 css:'div li span'").find { |x| 
x["html"].include? ("figure") }

Or:

menu_figure = query("WebView index:0 css:'div li span'", :html).find { |x| 
x.include? ("figure") }

 

If you have any question/suggestion, just let me know.

Thank you guys ! See you next week 🙂

4 thoughts on “Filtering an element using its property in arrays – calabash

  1. Hi,
    I want to understand the logic in writing calabash query like query (“view marked:’——–‘”)
    and we pass some property like :text :model from are we getting these parmeters .

    1. Hi avaneesh,
      this query will search the view wit the property marked equal “—“, if you pass some property in the query as :text or :model, you will have the result of the property of the element found.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.