'Appium Ruby - Can't Scroll To Accessibility_ID

http://appium.io/docs/en/commands/interactions/touch/scroll/

I want to scroll to an element. I keep getting an error. Fix may be simple but I'm totally lost.

Error: "undefined method `scroll' for #<Appium::TouchAction:0x000055d15d31c980> (NoMethodError)"

I am on:

  • Linux Mint
  • Ruby version 2.5.1p57
  • touch_action gem (1.3.3)
  • appium_lib gem (10.6.0)
  • appium_lib_core gem (3.7.0)

Below is my code.

require 'appium_lib'
require 'touch_action'
#require 'selenium-webdriver'

server_url = "http://127.0.0.1:4723/wd/hub"

opts = {
         caps: {
           platformName: :Android,
           platformVersion: 9,
           deviceName: :'Android Emulator',
           app: 'TheApp-v1.9.0.apk',
           newCommandTimeout: 600,
           automationName: :Appium,
           javascript_enabled: true
         }
  }


driver = Appium::Driver.new(opts, true)
driver.start_driver
ta = Appium::TouchAction.new.driver

sleep 5

scroll1 = ta.scroll_to(:accessibility_id, "Verify Phone Number")
scroll1.perform

sleep 2

print "Completed Successfully!"

driver.driver_quit


Solution 1:[1]

scroll_to has historically been flaky in Ruby Appium. I'd suggest writing your own logic similar to the following:

ta = Appium::TouchAction.new.driver
swipeUp = ta.swipe(startX, startY, endX, endY, duration)
clicked = false

(0...times).each do
    swipeUp.perform
    unless verifyPhoneNumber.isDisplayed
        verifyPhoneNumber.click
        clicked = true
    end
    break if clicked == true
end

My Ruby and Appium are a bit rusty; apologies if there are any errors above, but you should get the gist.

For reusability, I'd probably create a function with this logic that returns the element you were attempting to scroll to.

Solution 2:[2]

Following Worked for me (solution is for Ruby+Appium+Android)

require 'rubygems' require 'appium_lib'

desired_caps = {
      "appium:deviceName": "055542505S003131",
      "platformName": "android",
      "appium:appPackage": "app.endometriose.android",
      "appium:noReset": true,
      "automationName": "UiAutomator2",
      "appium:appActivity": "host.exp.exponent.MainActivity",
      "app": "/users/user/myApp.apk"
  }

appium_driver = Appium::Driver.new({'caps' => desired_caps, }, true)
 
# Scroll

        appium_driver.scroll_to("Button")
**Note:** scroll_to methods takes visible text of the element and scroll to it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike Collins
Solution 2 Muhammad Ateq Ejaz