How to make the script to wait until Swipe performed in device?

I’m trying to use swipe(startx,starty,endx,endy,duration). Once swiping command sent to device, Script is not waiting for the swipe action to be complete. Consider example, i mentioned duration as 3000ms (3 seconds). But Script is moving next line to code once swipe action is injected into the device (not waiting for 3 seconds). Right now To overcome this, I’m using Thread.sleep(). is there any better option to wait until swipe action performed in device

use explicit wait instead of Thread.sleep -

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(BY-LOCATOR-STRATEGY-HERE));

@Suman_Bala I think you are not getting my question. Consider a scenario, i need to swipe to element which is at the lower bottom or bottom. I created a logic by using the required element position
if position y is greater than screen size (element is not visible) means, i need to do swipe in while loop.
im injecting swiping action to the device with duration 3000. The Control is moving out from swipe method once touch sequence is injected into the device. It is not waiting for device to complete the touch sequence (which take 3000 millisecond to completed). Thread.sleep is current option to stop the execution till the action is performed in the device.

@balajig18 - Ah! try the below code then. This code checks if elements is displayed or not. If not then swipe -

    public void scrollToElement(String elementStr) {
		// calculate the screen size and get the coords for the swipe
		Dimension screenSize = driver.manage().window().getSize();
		int screenWidth = screenSize.getWidth() / 2;
		int screenHight = screenSize.getHeight() - 20;
		// this swipes down the screen until the given element is visible
		if (!driver.findElement(By.xpath(elementStr)).isDisplayed()) {
			do {
				driver.swipe(screenWidth, screenHight, screenWidth, screenHight - 600, 1000);
			} while (!driver.findElement(By.xpath(elementStr)).isDisplayed());
		}
	}

i know this logic Suman_Bala. Problem statement is driver.swipe will not wait for duration time that we specify. It just injected touch sequence command to the device and moved to next line of code immediately. if we have accessing the required element (click or position) before swipe action completes, we may face abnormal behavior in device.

@balajig18 Please could you post your test code here along with error logs? it’s really difficult to find the solution without looking at test code :slight_smile: