我试图通过获取两个元素的边界然后从一个点移动到另一个点来滚动,但我遇到了这个异常:
例外:
org.openqa.selenium.InvalidElementStateException: Unable to perform W3C actions. Check the logcat output for possible error reports and make sure your input actions chain is valid.
Build info: version: '4.8.1', revision: '8ebccac989'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.6'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [1f634b6a-e3fe-4f06-afc1-1e9afbb89278, actions {actions=[org.openqa.selenium.interactions.Sequence@3d53e6f7]}]
Capabilities {appium:app: apps\ptcl.apk, appium:appPackage: com.ufoneselfcare, appium:automationName: UiAutomator2, appium:databaseEnabled: false, appium:desired: {app: apps\ptcl.apk, automationName: UiAutomator2, deviceName: LDPlayerTwo, newCommandTimeout: 1000, platformName: android, platformVersion: 9, timeouts: 9999999, udid: emulator-5554}, appium:deviceApiLevel: 28, appium:deviceManufacturer: samsung, appium:deviceModel: SM-S908N, appium:deviceName: emulator-5554, appium:deviceScreenDensity: 320, appium:deviceScreenSize: 900x1600, appium:deviceUDID: emulator-5554, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:newCommandTimeout: 1000, appium:pixelRatio: 2, appium:platformVersion: 9, appium:statBarHeight: 48, appium:takesScreenshot: true, appium:udid: emulator-5554, appium:viewportRect: {height: 1552, left: 0, top: 48, width: 900}, appium:warnings: {}, appium:webStorageEnabled: false, platformName: ANDROID, timeouts: 9999999}
Session ID: 1f634b6a-e3fe-4f06-afc1-1e9afbb89278
我的Java代码
public void swipeUpUsingElementBounds(By firstElement, By secondElement, By targetElement,int x1, int y1,int x2, int y2) throws InterruptedException {
WebElement element1 = driver.findElement(firstElement);
WebElement element2 = driver.findElement(secondElement);
Point s = element1.getLocation();
Point s1 = element2.getLocation();
int startX = s.getX() + element1.getSize().getWidth() - x1;
int startY = s.getY() + element1.getSize().getHeight() - y1;
int endX = s1.getX() + element2.getSize().getWidth() - x2;
int endY = s1.getY() + element2.getSize().getHeight() - y2;
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence sequence = new Sequence(finger, 1);
sequence.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(),endX, endY ));
sequence.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
sequence.addAction(new Pause(finger, Duration.ofMillis(350)));
sequence.addAction(finger.createPointerMove(Duration.ofMillis(350), PointerInput.Origin.viewport(), startX, startY));
sequence.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
boolean isVisbile = isDisplayed(targetElement);
while (!isVisbile) {
Thread.sleep(2000);
driver.perform(Collections.singletonList(sequence));
isVisbile = isDisplayed(targetElement);
}
}
我已经调试了我的代码并更改了元素。它在操作时可见且可交互。我不确定它为什么会抛出异常。谁能帮我解决这个问题吗?我将非常感激
我刚刚通过调整边界值解决了这个问题。在我上面问题中所述的Java方法中,元素的边界由startX、startY、endX和endY表示。