Thursday, 9 May 2013

Calabash-IOS: Tips to search elements in View and webview

Calabash supports identification of view both using xpath & CSS

Its confirmed in in here https://groups.google.com/forum/#!msg/calabash-ios/nubfmY-6jbM/aSoYtW9mT8cJ

But this information is missing in wiki page

Usage :

Using CSS to identify elements : query("webView css:'#header'")
for xpath identification replace css by xpath and specify the path.

In Calabash-IOS there is no way to get source of HTML page, Getting elements from page

can be bit tricky, There are several possibilities to get past this 

check my video on this www.youtube.com/watch?v=w5rxvI3w2Ss

And also check below video






 

1) Use query("webView css:'*'") to get all associated elements on page then search for text you are looking at.
Index of results returned from query can be used to identify elements
Example:

res=query("webView css:'*'")
res[12] - could be the element you may want to verify

2) To verify if object is shown on screen .empty? can be very handy
 res=query("view text:'SomeText'").empty? # res is false if element is present
 use begin rescue block (in Ruby) to catch these exceptions and handle them


3) use regular expression 
query("view {text LIKE '*hello*'} ")

4) Using variables in search
text_to_check="hello"
query("view {text LIKE '*#{text_to_check}*'} ") 

5) Looping up and down until text found


while(true)
  begin 
    #check text found and click
  rescue
    #if there was any exception reported
    scroll("view",:down)
  end

end  

or 
wait_poll(:until_exists => "label text:'Cell 22'", :timeout => 20) do
  scroll("tableView", :down)
end
 
6)For converting case use upcase function
"hello".upcase

7) to check first & last result of array
arr=query("view {text LIKE '*#{text_to_check}*'} ")
arr.first 
arr.last  



1 comment:

  1. Best place to learn Appium Android IOS Automation Testing Training in Chennai
    Go for Appium training in chennai for real time mobile automation testing training with real time project support.
    UI Automation Tools with real time scenarios You can contact 8122241286 for Best APPIUM and selenium Training in Chennai

    ReplyDelete