【问题标题】:Scroll automation appium滚动自动化应用程序
【发布时间】:2018-06-05 00:51:42
【问题描述】:

我在移动设备上使用 Ruby 和 Appium 进行自动化操作,我需要访问超出范围的卡,我正在使用所有可能的方法,但它只是发生错误......有人有解决方案吗?我需要将 Recycler 视图一路向下

编辑: 代码

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

【问题讨论】:

  • 请在此处添加您迄今为止尝试过的代码 sn-p,以便我可以更有效地帮助您

标签: ruby selenium appium


【解决方案1】:
  • 首先获取元素(即卡片)
  • 然后添加下面的代码

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

希望对您有所帮助。如果您需要更多信息,请在此处发表评论

编辑:

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

这里的驱动程序是您用于自动化的驱动程序,即appium驱动程序。这里 card 是您想要获取并向上滚动到它的元素。

【讨论】:

  • 对不起,我没有强调我在移动端开发自动化,这个功能是否也适用于移动端?
  • 当然可以。只需将您的相关变量放在相关部分或刚刚过去您的代码 sn-p 我将为您输入确切的代码
  • Marvel,Recycler视图的id叫做list,我想往下滚动到最后停止,方法行不通?
  • 请分享您的代码 sn-p 您到目前为止所尝试的内容,以便我们修复您的代码。
  • /home/romeu/Documentos/SGV-MOBILE/features/controller/auditoria_controller.rb:29:语法错误,意外的 tIDENTIFIER,期望关键字_end JavascriptExecutor jse = (JavascriptExecutor)driver; ^ (语法错误)
【解决方案2】:

在红宝石中:

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

这将滚动到您正在寻找的元素,即使它不在屏幕上。您应该能够修改以与 Java 一起使用。

【讨论】:

  • 不幸的是,这似乎不再适用于 Appium 1.9.1。即使在元素进入视野后,可见状态仍然为假。似乎需要单击才能更新。触摸可能是更好的选择。
【解决方案3】:

scroll_to_exact(elementname) 应该为您完成这项工作!这将滚动到元素,直到指定可见。这是在 Appium_lib 中的 ruby​​

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-21
    • 2014-07-12
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多