使用 Appium 自动滚动到元素在 android 中不起作用

问题描述 投票:0回答:1

我正在尝试自动化 Android 应用程序。在其中我需要向下滚动到一个元素,并且给定的滚动代码不起作用

Appium 滚动代码不起作用

我已经尝试过这段代码

MobileElement l=driver.findElement( io.appium.java_client.MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollIntoView(new UiSelector().text(\"Link Patient to Doctor\");"));
l.click();

也尝试过这个代码

MobileElement li=driver.findElement(MobileBy.
 * AndroidUIAutomator("new UiScrollable(new    UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"Link Patient to Doctor\").instance(0))"
 * ));li.click();

页面应向下滚动到给定文本

我的appium版本是2.0.0-beta.71 npm 是 9.5.1

但它没有向下滚动并显示错误:

org.open qa.selenium.InvalidSelectorException:无法解析选择器 表达式

new UiScrollable(new UiSelector().scrollIntoView(new UiSelector().text("Link Patient to Doctor")
:未闭括号 有关此错误的文档,请访问: https://www.seleniumhq.org/exceptions/invalid_selector_exception.html 构建信息:版本:'3.141.59',修订版:'e82be7d358',时间: '2018-11-14T08:17:03' 系统信息:主机:'DESKTOP-VQLLA2K',ip: '192.168.56.1',os.name:'Windows 10',os.arch:'amd64',os.version: '10.0',java.version:'19.0.1' 驱动程序信息: io.appium.java_client.AppiumDriver 功能 {app: D: pp-release.apk, appActivity: com.calculator_apps.MainAct..., 应用程序包:com.calculator_apps,自动化名称:UiAutomator2, 数据库启用:假,所需:{应用程序:D:pp-release.apk, appActivity:com.calculator_apps.MainAct ...,appPackage: com.calculator_apps,自动化名称:UiAutomator2,设备名称: 三星,平台名称:android,平台版本:10},deviceApiLevel: 29、设备制造商:samsung,设备型号:SM-A305F,设备名称: RZ8M5181Y3M,设备屏幕密度:420,设备屏幕尺寸:1080x2340, 设备UDID:RZ8M5181Y3M,javascriptEnabled:true, locationContextEnabled:假,networkConnectionEnabled:真, PixelRatio:2.625,平台:LINUX,平台名称:Android, 平台版本:10,statBarHeight:83,takeScreenshot:true, viewportRect:{高度:2048,左侧:0,顶部:83,宽度:1080},警告: {}, webStorageEnabled: false} 会话 ID: 9641d029-12e2-4f87-bab0-86d49bcbeaa2 *** 元素信息:{Using=-android uiautomator, value=new UiScrollable(new UiSelector().scrollIntoView(new UiSelector().text("将患者链接到医生");}

如果有人知道解决办法请回复

java selenium-webdriver appium-android
1个回答
0
投票

尝试一下您的代码中存在问题。尝试这个。 driver.findElement(AppiumBy.androidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().text("WebView"));")).click();

© www.soinside.com 2019 - 2024. All rights reserved.