【问题标题】:How to pass argument when extend Robotframework AppiumLibrary to call appium execute_script function扩展Robotframework AppiumLibrary以调用appium execute_script函数时如何传递参数
【发布时间】:2021-11-24 03:30:25
【问题描述】:

我已经创建了一个包含以下内容的 python 文件

from robot.libraries.BuiltIn import BuiltIn

def scroll_page_to_the_bottom():
    BuiltIn().get_library_instance('AppiumLibrary').execute_script("mobile: scroll", {'direction': 'down'})

当我使用关键字 scroll_page_to_the_bottom 从机器人文件调用时,我收到错误 TypeError: too many positional arguments

我认为我的脚本有问题,我尝试使用其他移动命令,例如 mobile: deviceInfo,它运行良好 这是我的代码BuiltIn().get_library_instance('AppiumLibrary').execute_script("mobile: deviceInfo")中的工作执行脚本@

我的问题是如何将带有参数的命令传递给execute_script

参考http://appium.io/docs/en/commands/mobile-command/index.html,我使用了正确的格式execute_script("mobile: scroll", {'direction': 'down'}),但机器人执行时出现错误TypeError: too many positional arguments

【问题讨论】:

  • 请显示完整的实际错误。
  • @BryanOakley 这是错误 TypeError: too many positional arguments

标签: python appium robotframework appium-android python-appium


【解决方案1】:

您的 Python 代码正在调用 AppiumLibrary 对象上的 execute_script() 方法,该对象来自 robotframework-appiumlibrary 包。此方法仅接收一个参数 (script),并且您传递了两个参数:1. 字符串 "mobile: scroll" 和 2. 字典 {'direction': 'down'}。因此出现TypeError: too many positional arguments 异常。

您给出的第二个示例有效,因为您传递了正确数量的参数:字符串"mobile: deviceInfo"

页面http://appium.io/docs/en/commands/mobile-command/index.html 记录了appium-python-client 包中的execute_script() 方法,这是一个不同的包。你调用的方法不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 2010-10-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    相关资源
    最近更新 更多