scroll and find in appium lib

2,006 views
Skip to first unread message

Satyajit Malugu

unread,
Sep 30, 2013, 7:34:51 PM9/30/13
to appium-...@googlegroups.com
Matthew,

Is there a scroll if required method in appium lib for android?

I currently have this and works pretty reliably for s_text

  def self.scroll_and_find(element_text)
    scroll_to element_text unless exists {s_text element_text}
    s_text element_text
  end

but it would be nice to have for other kinds of element finders (xpaths, buttons etc). This is becoming espeically relevant now we are also doing landscape testing.

-Satyajit

bootstrap online

unread,
Sep 30, 2013, 8:07:49 PM9/30/13
to Satyajit Malugu, appium-...@googlegroups.com
scroll_to looks for a text or content description match by invoking mobile find.
https://github.com/appium/ruby_lib/blob/2003589197a78d54f3d177abbf2335724c090e1e/lib/appium_lib/android/element/generic.rb#L105

You can call mobile find with a different array to find buttons. The
existing XPath implementation is not very good on Android so that's
not so easy to add.

I think scrolling will be removed from Appium soon as part of the new
standard so I haven't put more time into adding features. /cc @jlipps
> --
> http://appium.io
> ---
> You received this message because you are subscribed to the Google Groups
> "Appium-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to appium-discus...@googlegroups.com.
> Visit this group at http://groups.google.com/group/appium-discuss.
> For more options, visit https://groups.google.com/groups/opt_out.

bootstrap online

unread,
Sep 30, 2013, 8:11:27 PM9/30/13
to Satyajit Malugu, appium-...@googlegroups.com
In case it's not clear, anything with a text or content description
can be scrolled to. It's in no way limited to s_text.

Ritika Mishra

unread,
Oct 3, 2013, 3:10:30 AM10/3/13
to appium-...@googlegroups.com, Satyajit Malugu
Hi,

But how to scroll to RadioButton or a checkbox that is not bound to its displayed text. Developers have not even given any content-Desc to it (and are not even ready to add any). Xpath doesn't work. If i try using index number then its not at-all stable. Indexes completely depend on the number of check box/ radio button that show-up after scrolling. "ID" that we get through the hierarchy viewer will work only for API level 18+ (4.3).
Any suggestion or solution to this problem would be greatly appreciated.

Thanks,
Ritika

bootstrap online

unread,
Oct 3, 2013, 9:28:20 AM10/3/13
to Ritika Mishra, appium-...@googlegroups.com, Satyajit Malugu
Have the developers add a content description. You could also add it
for them. Content descriptions are very easy to set.

Anil Kumar

unread,
Oct 3, 2013, 12:02:50 PM10/3/13
to appium-...@googlegroups.com
Based on visible text, you can use siblings in xpath to reach to exact radio button.

Brent LaVelle

unread,
Oct 8, 2013, 3:07:32 PM10/8/13
to appium-...@googlegroups.com, Satyajit Malugu
I've just run in to this issue.  The elements that I want are off the bottom of the screen for smaller devices.  I can kludge in a swipe or flick but then I found this thread so I did this:

      browser.execute_script 'scroll_to', 'listing_bedrooms'
      browser.find_element :name, 'listing_bedrooms'

and got this: Selenium::WebDriver::Error::UnknownError: Not yet implemented. Please help us: http://appium.io/get-involved.html

Am I doing something wrong or is this something that needs to be added to Appium?

bootstrap online

unread,
Oct 8, 2013, 3:08:58 PM10/8/13
to Brent LaVelle, appium-...@googlegroups.com, Satyajit Malugu
Are you using Ruby? The scroll_to method that I'm using in Android
only works with the appium Ruby gem. If you're in a different
language, then you can either use the built in mobile scroll or port
the Ruby code.

Brent LaVelle

unread,
Oct 8, 2013, 4:54:20 PM10/8/13
to appium-...@googlegroups.com, Brent LaVelle, Satyajit Malugu
I am using Ruby, well my tests are written in it.  The appium server is the GUI on a mac.  The problem is coming from the other side of the bridge.  The Ruby code is getting a 501.  It looks like I wasn't using 'scroll to' correctly
This was bad> browser.execute_script 'mobile: scrollTo', 'listing_bedrooms
So I poked around and I'm thinking it should look more like this:
Less bad> browser.execute_script 'mobile: scrollTo', 'listing_bedrooms'
Now I get a Selenium::WebDriver::Error::NoSuchElementError
After some searching I've still not figured it out but I can keep searching from here.

bootstrap online

unread,
Oct 8, 2013, 4:56:55 PM10/8/13
to Brent LaVelle, appium-...@googlegroups.com, Satyajit Malugu

Brent LaVelle

unread,
Oct 8, 2013, 5:06:13 PM10/8/13
to appium-...@googlegroups.com, Brent LaVelle, Satyajit Malugu
Sorry I botched that last post.  The original really bad code was doing this
browser.execute_script 'scroll_to', 'listing_bedrooms'

Brent LaVelle

unread,
Oct 8, 2013, 5:25:22 PM10/8/13
to appium-...@googlegroups.com, Brent LaVelle, Satyajit Malugu
That is the one test that is failing for me:

Finished in 36 secs

  1) Error:
android/element/generic#test_0006_scroll_to:
Selenium::WebDriver::Error::NoSuchElementError: No such element.
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/response.rb:51:in `assert_ok'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/common/patch.rb:151:in `raw_execute'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/bridge.rb:612:in `execute'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/bridge.rb:333:in `executeScript'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/common/driver.rb:213:in `execute_script'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/driver.rb:571:in `mobile'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/android/element/generic.rb:115:in `scroll_to'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/driver.rb:201:in `rescue in block (4 levels) in promote_appium_methods'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/driver.rb:193:in `block (4 levels) in promote_appium_methods'
    /Users/blavelle/git/ruby_lib_android/lib/android/specs/android/element/generic.rb:33:in `block (2 levels) in <top (required)>'

12 runs, 12 assertions, 0 failures, 1 errors, 0 skips
delete 

bootstrap online

unread,
Oct 8, 2013, 5:31:53 PM10/8/13
to Brent LaVelle, appium-...@googlegroups.com, Satyajit Malugu
I just ran the tests against an API 18 emulator and they all pass.
https://github.com/appium/ruby_console/blob/master/img/avd_settings.png

Finished in 2 mins 2 secs

98 runs, 122 assertions, 0 failures, 0 errors, 0 skips

Brent LaVelle

unread,
Oct 8, 2013, 6:42:03 PM10/8/13
to appium-...@googlegroups.com, Brent LaVelle, Satyajit Malugu
I ran just the android tests 'rake android' against a Nexus 4, a gennymotion emulator and just now a Nexus 7.  The Nexus 7 gave me a different error

  1) Error:
android/element/generic#test_0007_mobile find works before and after source:
JSON::ParserError: A JSON text must at least contain two octets!
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/json-1.8.0/lib/json/common.rb:155:in `initialize'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/json-1.8.0/lib/json/common.rb:155:in `new'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/json-1.8.0/lib/json/common.rb:155:in `parse'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/common/helper.rb:203:in `get_source'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/driver.rb:201:in `rescue in block (4 levels) in promote_appium_methods'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/driver.rb:193:in `block (4 levels) in promote_appium_methods'
    /Users/blavelle/git/ruby_lib_android/lib/android/specs/android/element/generic.rb:41:in `block (2 levels) in <top (required)>'

13 runs, 15 assertions, 0 failures, 1 errors, 0 skips
delete 

I'm looking over the test and I don't see what the scroll_to receiver is, Rubymine is confused too.  I'm guessing there is an include somewhere that adds that method.

I then tried to make an AVD with your setting on my Mountain Lion Mac I could not set the CPU/ABI so it stayed ARM (armeabi-v7a)  (NOTE: if I change the target to 4.2.2 API Level 17, I can modify this)

I got the same error as the N4 and Genymotion

Finished in 54 secs

  1) Error:
android/element/textfield#test_0001_textfields:
Selenium::WebDriver::Error::NoSuchElementError: No such element.
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/response.rb:51:in `assert_ok'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/common/patch.rb:151:in `raw_execute'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/bridge.rb:612:in `execute'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/remote/bridge.rb:333:in `executeScript'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/common/driver.rb:213:in `execute_script'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/driver.rb:571:in `mobile'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/android/element/generic.rb:73:in `text'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/driver.rb:201:in `rescue in block (4 levels) in promote_appium_methods'
    /Users/blavelle/.rvm/gems/ruby-1.9.3-p448/gems/appium_lib-0.11.1/lib/appium_lib/driver.rb:193:in `block (4 levels) in promote_appium_methods'
    /Users/blavelle/git/ruby_lib_android/lib/android/specs/android/element/textfield.rb:16:in `block (2 levels) in <top (required)>'

14 runs, 18 assertions, 0 failures, 1 errors, 0 skips
    3.times { back }
post /back
post /back
post /back
delete 
blavelle@HA002499 ~/git/ruby_lib_android\> 

Brent LaVelle

unread,
Oct 8, 2013, 6:42:38 PM10/8/13
to appium-...@googlegroups.com, Brent LaVelle, Satyajit Malugu
BTW, I really appreciate all the help.  It is nice to use tools with an active community.

bootstrap online

unread,
Oct 8, 2013, 11:52:19 PM10/8/13
to Brent LaVelle, appium-...@googlegroups.com, Satyajit Malugu
"JSON::ParserError: A JSON text must at least contain two octets!"
means uiautomator didn't send the xml dump.

I think the issue is you're not on API 18.
https://github.com/appium/appium/issues/1078

I'm focusing on testing API 18 and will be looking into old Android
support via Espresso when it's released. Selendroid probably has a way
to scroll so you could look into that.

Brent LaVelle

unread,
Oct 9, 2013, 10:50:19 AM10/9/13
to appium-...@googlegroups.com, Brent LaVelle, Satyajit Malugu
We are currently supporting API levels 15 and up.  I managed to work around the issue swiping so I think I'm just going to write a find_element_scrolling method that will try to find it by using swipe to scroll around the screen.  As we deprecate old API levels I'll be able to remove this hack.

Thanks for showing me that this was a dead end for now.

Satyajit Malugu

unread,
Oct 9, 2013, 4:27:47 PM10/9/13
to appium-...@googlegroups.com, Brent LaVelle, Satyajit Malugu
I got a problem with nexus 7 and got the same
"A JSON text must at least contain two octets"

bootstrap online

unread,
Oct 9, 2013, 4:29:52 PM10/9/13
to Satyajit Malugu, appium-...@googlegroups.com, Brent LaVelle
The JSON issue is being tracked here:
https://github.com/appium/appium/issues/1269
Reply all
Reply to author
Forward
0 new messages