You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

扩展RobotFramework AppiumLibrary调用execute_script如何正确传参

问题原因

你遇到的参数报错是因为AppiumLibrary对execute_script方法的封装规则和原生Appium Python客户端不同,额外参数的传递格式存在差异。

解决方法

方法1:调整execute_script参数格式

将参数字典封装到列表中作为第二个参数传入即可,修改后代码如下:

from robot.libraries.BuiltIn import BuiltIn

def scroll_page_to_the_bottom():
    appium_lib = BuiltIn().get_library_instance('AppiumLibrary')
    # 所有脚本参数需要放在同一个列表中传入
    appium_lib.execute_script("mobile: scroll", [{'direction': 'down'}])

方法2:使用专用execute_mobile_command方法(更推荐)

AppiumLibrary内置了专门用于调用mobile:系列命令的execute_mobile_command方法,无需处理参数格式,直接传入命令名和对应参数即可,兼容性更好:

from robot.libraries.BuiltIn import BuiltIn

def scroll_page_to_the_bottom():
    appium_lib = BuiltIn().get_library_instance('AppiumLibrary')
    # 第一个参数为mobile: 后面的命令名称,无需加前缀
    appium_lib.execute_mobile_command("scroll", direction='down')

内容的提问来源于stack exchange,提问作者J. Doem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 23:15:05