Appium - Ruby - iOS - swiping to an element that isn't visible


#1

I’ve been looking at this for a bit and can’t seem to find a good reference for Ruby on how to swipe to a particular element. I need some help with the format. Seen plenty of Java references but can’t seem to convert the code to Ruby.

  1. First would like to know what we should be using to navigate elements in a scroll. What is the current correct method with a snippet of example Ruby code. Everything I see explanations for is deprecated or just doesn’t work for me. The only swipe I’ve gotten to work is here ( and I read this was being deprecated as well):

direction1 is down

while (!find_element(name: element1).displayed?)
@driverAppium.swipe(direction: direction1)
end

This will work to scroll but it is pretty frustrating that the default scroll goes past objects that aren’t currently visible. Basically I look for an item but since it isn’t visible and gets scrolled offscreen I can’t flag it using this method. My attempts at using the element option have failed. Is there a good reference somewhere that has ruby examples (the appium docs have not proved a good reference for me to implement Ruby). I’d just like to see an example of how to scroll to an element in a Native iOS code. I’m using a simulator or live device. Thanks for any help.

I’ve been trying to use TouchAction but can’t seem to get the ruby code to work. Keep getting errors. I’m sure it’s how I’m formatting it. I have x/y coordinates, and accessibility_id for the item I’m trying to navigate to. What would be example code to navigate to

Start_x = 15
Start_y = 251

End_x = 15
End_y = 340

Aceesibility_id = “Log Out”


#2

Here are my scroll methods. We use the javascript executor:

  def swipe_left
    log.info 'Swiping left'
    apm.driver.execute_script('mobile: scroll', direction: 'right')
  end

  def swipe_right
    log.info 'Swiping right'
    apm.driver.execute_script('mobile: scroll', direction: 'left')
  end

  def swipe_up
    log.info 'Swiping up'
    apm.driver.execute_script('mobile: scroll', direction: 'down')
  end

  def swipe_down
    log.info 'Swiping down'
    apm.driver.execute_script('mobile: scroll', direction: 'up')
  end

  def scroll_to_element(element)
    apm.driver.execute_script('mobile: scroll', name: element.name)
  end

#3

Thanks for the quick response - I’m looking for a way to use ruby/appium only without anything else. It’s a basic function. I can’t believe there is nothing built into ruby/appium to perform these actions. Swipe does work in the example I have but it isn’t precise. Thanks for any help. I’ve been trying lots of things and nothing seems to work for me except swipe with a single parameter.


#4

Sorry, I’m a bit more pragmatic. This works for us, and has for a long time. If you don’t find what your are looking for give it a try & good luck.


#5

Thanks I did try it. I’m missing something in our ruby, cucumber, Appium environment to get this to work. Not really feasible for me to force everyone else to modify a long running environment so I can get my code to work especially when I know there has to be a way to do this within Ruby/Appium.


#6

I tried it again and your code worked. Thank you very much. When I cut and pasted it something must be added from the web to my environment. I tried this exact code before and it failed for me. I had it commented out. You telling me it worked got me to poke at it more and I eventually just manually typed it in and then it worked. I can see zero difference between the two pieces of code.
Using intellij I wouldn’t think copying from a web page would add hidden characters and cause me a problem but it obviously did. Learn something new every day. Thanks again.


#7

The apm.driver.execute_script(‘mobile: scroll’, name: element.name) no longer seems to work with Appium 1.9.1. The element visible status remains false even after it scrolls into the display. Just an FYI. Something changed and it has been causing me numerous headaches. The visible status only seems to update after a click.


#8

I was just going to try out 1.9.1 soon, so that’s bad news for me. I’ll try & report my results back when I can.


#9

Others are reporting the same issue. Keep in mind that if you upgrade xcode to run with iOS 12.0 you may not be able to revert to Appium versions prior to 1.9x. I got errors when I tried to downgrade because 1.8 says it doesn’t support my version of xcode. Personally I’d try 1.9.1 before upgrading xcode to latest (if possible)


#10

Thanks for the advice. I’m a slow adopter for these very reasons.


#11

Normally I go kicking and screaming but I was forced to update xcode so had no choice.


#12

@candyman888
I also using the same environment (ruby cucumber with appium) but am facing slowness on script execution after upgrading to iOS 12 env. specifically during the find elements. if possible please share your capabilities and swipe code details