I am attempting to scroll by obtaining the bounds of two elements and then moving from one point to the other, but I am encountering this exception:

Exception:


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

My Java Code

 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);
    }
}

I have debugged my code and also changed the element. It is visible and interactable at the time of the action. I'm not sure why it is throwing an exception. Can anyone help me solve this problem? I would be very thankful

1

There are 1 best solutions below

0
Imran On

I just resolved it by adjusting the bounds values. In my Java method stated in my question above, the elements' bounds are represented by startX, startY, endX, and endY.