One more thing, you can enable touch and pointer option for observing touch action, From android mobile Settings > Developer option > Input > Enable Pointer location and Show touches, observe the touch action and change the start point / end point / time duration from swipeVertical(driver,0.9,0.1,0.5,3000);
as you need.
Hereâs how I placed it. I just copied the code above.
I called the method to my test.java class:
with Regards to Settings, I donât have also the 'Enable Pointer location and Show touches â option. Iâm currently using Samsung Galaxy S8. Thank you. @Al_Imran
I have tried this but no effect takes place
I have 1 question how u get the co-ordinates
0.9,0.1,0.5,3000
And also when I tried this
Dimension dim= SwipeHomeButton.getSize();
int height= dim.getHeight();
int width = dim.getWidth();
int y = (int)(height*.20);
int startx=(int)(width*.75);
int endx=(int)(width*.35);
driver.swipe(startx, y, endx, y,500);
new TouchAction(driver).press(y, startx).waitAction(5000).moveTo(y, endx).release().perform();
It pulled from the top on my android phone
It looks like it is not able to get the proper co-ordinates
Can u plzz help me with this
Hi
I am new to Appium and struggling on calling a swipe method from left to right.
As per you video, driver is not having method called swipe in its intelligence.
I have tried using calling TouchAction class as well but while giving driver as argument it is
throwing the below error all the time. I am Struck and not able to move further.
Please help here
Still No progress. I am getting below error.
Below is my Capability SetUp. Please let me know If any where am doing wrong.
public class ExampleHorizontalSwipe {
//AndroidDriver driver;
WebDriver driver;
@Test(priority=0)
public void setUp() throws MalformedURLException
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "NexusTest");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "5.0.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("...");
capabilities.setCapability("appActivity", "...");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
// driver = new AndroidDriver(new URL(âhttp://127.0.0.1:4723/wd/hubâ), capabilities);
// driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
Hi After using the below method, console show script pass successfully but execution was not happening from left to right for a specific element. please help where am i missing.
public class ExampleHorizontalSwipe {
AndroidDriver driver = null;
}
TouchAction act = new TouchAction(driver);
act.longPress(200, 180, Duration.ofSeconds(2)).moveTo(600, 180).release().perform();
Hi @praveen0314 can you please post your code, after making which changes this swipe started working to you
Hi All, Finally I could able to resolve the issue of swiping for
Android
Hybrid App
Samsung 8 Device
before start of swiping use the switching to the Native context, after doing the swipe action
//Find swipe start and end point from screen's.
//Find startx point which is at right side of screen.
int startx = (int) (size.width * 0.70);
//Find endx point which is at left side of screen.
int endx = (int) (size.width * 0.30);
//Find vertical point where you wants to swipe. It is in middle of screen height.
int starty = size.height / 2;
System.out.println("startx = " + startx + " ,endx = " + endx + " , starty = " + starty);
//Swipe from Right to Left.
if(swipingDirection == Swipe.Left)
((AndroidDriver<WebElement>)getInstance()).swipe(startx, starty, endx, starty, 2000);
//Swipe from Left to Right.
if(swipingDirection == Swipe.Right)
((AndroidDriver<WebElement>)getInstance()).swipe(endx, starty, startx, starty, 2000);
switch back to WebContext to continue working with elements. Hope this solution helps
Watch it https://youtu.be/BkFQgtfzkMI22
Sorry Kumar, I was missed you request.
You have done great !!! anyways for your information please find the below code which i have used to swipe left to right
AndroidDriver driver = null;
TouchAction act = new TouchAction(driver);
act.longPress(200, 180, Duration.ofSeconds(3)).moveTo(790, 180).release().perform();.
You can watch this video : https://youtu.be/BkFQgtfzkMI13
Iâve consolidated my findings in https://discuss.appium.io/t/swipe-scroll-best-practice-with-java-client-5/18589/1722
@Telmo_Cardoso
This solution not working, while Iâm using java-client 5.0.4. Its showing error at duration
and suggested change it to Duration.ofDays(duration)
, I have tried it but not working. could you please help for solving this problem.
Thanks it is working cool @Telmo_Cardoso
For java-client 5.x.x new solution is:
public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height * anchorPercentage);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * finalPercentage);
new TouchAction(driver).press(startPoint, anchor).waitAction(Duration.ofMillis(duration)).moveTo(endPoint, anchor).release().perform();
}
public static void swipeVertical(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.width * anchorPercentage);
int startPoint = (int) (size.height * startPercentage);
int endPoint = (int) (size.height * finalPercentage);
new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofMillis(duration)).moveTo(anchor, endPoint).release().perform();
}
To swipe in the latest version 5.0+ . You can watch this video : https://www.youtube.com/watch?v=9rHe0r6YsVg17
I have followed the reference from the above discussion but nothing got at the o/p on the real device, Please help.
Code for swipe from right to left-
Dimension size=driver.manage().window().getSize();
System.out.println(size);
int startx= (int)(size.width0.70);
int endx= (int)(size.width0.30);
int starty=size.height/2;
long duration=0;
int y=0;
new TouchAction(driver).press(startx, y).waitAction(Duration.ofMillis(duration)).moveTo(endx, y).release().perform();
Iâm getting the "trueâ status in the Logs, but nothing is implementing on the real device-
logs-
[debug] [MJSONWP] Calling AppiumDriver.performTouch() with args: [[{âactionâ:âpressâ,âoptionsâ:{âxâ:503,âyâ:0}},{âactionâ:âwaitâ,âoptionsâ:{âmsâ:0}},{âactionâ:âmoveToâ,âoptionsâ:{âxâ:216,âyâ:0}},{âactionâ:âreleaseâ,âoptionsâ:{}}],â0a9677b1-78bf-407c-a744-8039daa28a61â]
[debug] [AndroidBootstrap] Sending command to android: {âcmdâ:âactionâ,âactionâ:âswipeâ,âparamsâ:{âstartXâ:503,âstartYâ:0,âendXâ:216,âendYâ:0,âstepsâ:22}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {âcmdâ:âactionâ,âactionâ:âswipeâ,âparamsâ:{âstartXâ:503,âstartYâ:0,âendXâ:216,âendYâ:0,âstepsâ:22}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: swipe
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][720,1184]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][720,1184]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Swiping from [x=503.0, y=592.0] to [x=216.0, y=592.0] with steps: 22
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.performTouch() result: true
[HTTP] <-- POST /wd/hub/session/0a9677b1-78bf-407c-a744-8039daa28a61/touch/perform 200 468 ms - 76
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {âstatusâ:0,âvalueâ:true}
[BaseDriver] Shutting down because we waited 45 seconds for a command
[debug] [AndroidDriver] Shutting down Android driver
[Appium] Closing session, cause was âNew Command Timeout of 45 seconds expired. Try customizing the timeout using the ânewCommandTimeoutâ desired capabilityâ
[Appium] Removing session 0a9677b1-78bf-407c-a744-8039daa28a61 from our master session list
[debug] [ADB] Getting connected devicesâŚ
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running âC:\Users\SJ\AppData\Local\Android\Sdk\platform-tools\adb.exeâ with args: ["-P",5037,"-s",âX606A1ZH69090204â,âshellâ,âamâ,âforce-stopâ,âcom.letsdogether.dogetherâ]
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devicesâŚ
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running âC:\Users\SJ\AppData\Local\Android\Sdk\platform-tools\adb.exeâ with args: ["-P",5037,"-s",âX606A1ZH69090204â,âshellâ,âinputâ,âkeyeventâ,3]
[debug] [AndroidBootstrap] Sending command to android: {âcmdâ:âshutdownâ}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state âstoppingâ
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {âcmdâ:âshutdownâ}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {âstatusâ:0,âvalueâ:âOK, shutting downâ}
[debug] [AndroidBootstrap] [UIAUTO STDOUT] close [socket][/127.0.0.1:4724]
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state âstoppedâ
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devicesâŚ
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running âC:\Users\SJ\AppData\Local\Android\Sdk\platform-tools\adb.exeâ with args: ["-P",5037,"-s",âX606A1ZH69090204â,âshellâ,âpsâ]
[ADB] No uiautomator process found to kill, continuingâŚ
[debug] [UiAutomator] Moving to state âstoppedâ
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Getting connected devicesâŚ
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running âC:\Users\SJ\AppData\Local\Android\Sdk\platform-tools\adb.exeâ with args: ["-P",5037,"-s",âX606A1ZH69090204â,âshellâ,âamâ,âforce-stopâ,âio.appium.unlockâ]
[debug] [AndroidDriver] Not cleaning generated files. Add clearSystemFiles
capability if wanted.
As we can see in the logs x value changes from 503 to 216 but nothing is happening on the real device
In Java Client: 5.x.x, itâs working fine but while I have updated to 6.1.0 itâs not working and showing error, how I can resolve please help me!
public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height * anchorPercentage);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * finalPercentage);
new TouchAction(driver).press(startPoint, anchor).waitAction(Duration.ofMillis(duration)).moveTo(endPoint, anchor).release().perform();
}
Those methods were removed.Try to adapt your code to the new methods available.
For instance:
void swipeCoordinates(AppiumDriver driver, int startX, int startY, int endX, int endY, int duration) throws Exception {
new TouchAction(driver).press(point(startX, startY)).waitAction(waitOptions(Duration.ofMillis(duration)))
.moveTo(point(endX, endY)).release().perform();
}
This works for me.
public void swipeHorizontal(int duration, String dragMeString) throws Exception {
WebElement dragMe = getElementByProperty(dragMeString);
new TouchAction(driver)
.press(PointOption.point(dragMe.getLocation().getX() + (dragMe.getSize().width - 20),
dragMe.getLocation().getY() + (dragMe.getSize().height / 2)))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration)))
.moveTo(PointOption.point(dragMe.getLocation().getX(),
dragMe.getLocation().getY() + (dragMe.getSize().height / 2)))
.release().perform();
}
This should work
Dimension size = driver.manage().window().getSize();
System.out.println(size.height+âheightâ);
System.out.println(size.width+âwidthâ);
System.out.println(size);
int startPoint = (int) (size.width * 0.99);
int endPoint = (int) (size.width * 0.15);
int ScreenPlace =(int) (size.height0.40);
int y=(int)size.height20;
TouchAction ts = new TouchAction(driver);
for(int i=0;i<=3;i++) {
ts.press(PointOption.point(startPoint,ScreenPlace ))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
.moveTo(PointOption.point(endPoint,ScreenPlace )).release().perform();