使用JavascriptExecutor执行scrollGesture时ImmutableMap.of参数不匹配问题
问题解决:ImmutableMap.of参数不匹配导致的滚动手势执行错误
错误原因
错误提示翻译:ImmutableMap类的of(K, V, K, V, K, V, K, V, K, V)方法无法适配给定的参数(String, int, String, int, String, int, String, int, String, String, String, double)
本质是Guava的ImmutableMap.of()方法有重载限制——它只提供了最多包含5个键值对的重载版本(对应10个参数),而你这里传入了6个键值对(left、top、width、height、direction、percent),共12个参数,找不到匹配的重载方法,所以报错。
修复方案
当需要构建包含5个以上键值对的ImmutableMap时,改用ImmutableMap.builder()模式来创建对象,修改后的代码如下:
boolean canScrollMore = (Boolean) ((JavascriptExecutor) driver).executeScript("mobile: scrollGesture", ImmutableMap.<String, Object>builder() .put("left", 100) .put("top", 100) .put("width", 200) .put("height", 200) .put("direction", "down") .put("percent", 3.0) .build() );
说明
ImmutableMap.builder()不受键值对数量限制,通过链式调用put()方法添加所有参数,最后调用build()生成ImmutableMap对象,完美适配你的滚动手势参数需求。
内容的提问来源于stack exchange,提问作者parveen banu
相关产品推荐
相关产品推荐

