Home > Programming, Programming, QA, Test and Automation Stuffs, Test and Automation Stuffs > Filtering an element using its property in arrays – calabash

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 🙂

Advertisements
  1. avaneesh
    December 14, 2014 at 4:13 am

    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 .

    • December 15, 2014 at 11:28 am

      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.

  2. Linh Nguyen
    June 4, 2016 at 9:41 am

    Hi,
    How to
    assert text in hybrid android application.
    help me!
    Thank!

    • June 4, 2016 at 3:42 pm

      Hey, you will probably need to use javascript to find the web elements.

  1. No trackbacks yet.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: