1

I'm doing an automation in Ruby and Appium on mobile, and I need to access a card that is out of range, and I'm using all possible methods and it just happens error ... Does anyone have a solution? I need to down the Recycler view all the way down

Edit: code

class AuditoriaController

  def initialize

    @util = UtilMethods.new
    @objects = PageAuditoria.new

    main = MenuPrincipal.new

    @menus = main.menus
    @tela_principal = main.tela_principal

    @objects_auditoria = @objects.tela_auditoria

  end

  def acessar_auditoria
    data_sync = find_element(:xpath, @tela_principal[:msg_sincronizacao]).text
    data_sync.slice!("Última atualização: ")

    t = Time.now

    while(t.strftime("%d/%m/%Y %H:%M:%S") != data_sync)
      btn_sync = find_element(:xpath, @tela_principal[:view_sync])
      btn_sync.click
      break;
    end


    list = find_element(:xpath, @tela_principal[:lista])
    list.scrollIntoView()

    #menu_auditoria = find_element(:xpath, @menus[:menu_auditoria])
    #if(menu_auditoria)
    #  @util.logger("ACHEI AUDITORIA")
    #end

  end

3 Answers3

0
  • First get the element(that is card)
  • Then add the below code

    browser.execute_script('arguments[0].scrollIntoView();', card);
    

Hope it will help you. If you need any more information just comment here

EDIT:

  JavascriptExecutor jse = (JavascriptExecutor)driver;
  jse.execute_script('arguments[0].scrollIntoView();', card)

Here driver is the driver you are using for automation that is appium driver. Here card is the element that you want to get and scroll upto it.

Mahmud Riad
  • 1,169
  • 1
  • 8
  • 19
  • Sorry, I did not stress that I'm developing automation on mobile, does this function also work for mobile? – Emanuel Bessa Dec 22 '17 at 11:20
  • Sure why not. Just put your relevant variable in relevant portion or just past your code snippet i will put the exact code for you – Mahmud Riad Dec 22 '17 at 11:22
  • Marvel, the id of the Recycler view is called list, I want to go to the end of the scroll down and stop, does the method work? – Emanuel Bessa Dec 22 '17 at 11:25
  • Please share your code snippet what you have tried so far so that we can fix up your code. – Mahmud Riad Dec 22 '17 at 11:34
  • /home/romeu/Documentos/SGV-MOBILE/features/controller/auditoria_controller.rb:29: syntax error, unexpected tIDENTIFIER, expecting keyword_end JavascriptExecutor jse = (JavascriptExecutor)driver; ^ (SyntaxError) – Emanuel Bessa Dec 22 '17 at 11:42
  • Please also refer to https://stackoverflow.com/questions/7565562/how-to-execute-javascript-in-ruby-written-webdriver-test for how to use javascriptexecutor in ruby – Mahmud Riad Dec 22 '17 at 11:53
  • Method has not yet been implemented (Selenium::WebDriver::Error::UnknownError) , Implement the method that I saw without tutorial and appear. complicated Method: list = find_element(:xpath, @tela_principal[:lista]) @driver.execute_script("list.scrollIntoView(true);", "AUDITORIA") – Emanuel Bessa Dec 22 '17 at 12:01
0

In ruby:

def scroll_to_element(element)
   @driverAppium.execute_script('mobile: scroll', name: element.name)
end

This will scroll to the element which you are looking for even if it is offscreen. You should be able to modify for use with Java.

Henry Woody
  • 14,024
  • 7
  • 39
  • 56
  • Unfortunately this no longer seems to work with Appium 1.9.1. The visible state remains false even after the element comes into view. A click seems to be required to get it to update. Touch is probably a better choice. – Mark Thompson Oct 10 '18 at 22:33
0

scroll_to_exact(elementname) should do the job for you! This will scroll to through the elements until the specified is visible. This is in Appium_lib for ruby

Emjey
  • 2,038
  • 3
  • 18
  • 33