hi guys,
i know most of them faced similar issue but Im not able to horizontal swipe, even with percentage, have tried the following
Using your method for Android, I get the below error in appium logs when I try for a horizontal swipe right to left. Using 5.0.4 and appium 1.7.2. Any ideas?
t.press(1000, 1500).waitAction(Duration.ofMillis(1000)).moveTo(0, 1500).release().perform();
[HTTP] --> POST /wd/hub/session/cd1cd37c-110a-43c6-a808-b6ff3eac33ac/touch/perform {“actions”:[{“action”:“press”,“options”:{“x”:1000,“y”:1500}},{“action”:“moveTo”,“options”:{“x”:0,“y”:1500}},{“action”:“release”,“options”:{}}]}
[debug] [MJSONWP] …
WebElement el = driver.findElement(By.xpath(“//div[@Class=‘slide’]//div[@Class=‘image’]//div[@Class=‘arrow’]”));
Point loc = el.getLocation();
String currentcontext = driver.getContext();
driver.context("NATIVE_APP");
Thread.sleep(5000);
TouchAction touchAction = new TouchAction(driver);
touchAction.press(loc.x, loc.y).moveTo(0, loc.y).release().perform();
driver.context(currentcontext);
Specs: appium client - 1.7.2
** UI automato rv1**
** java client 5.0.4**
** maven -project**
Can anyone post exact code for it, w.r.t id , xpath or text a dynamic one…please it would be of great help
Does it has to do anything with UIautomator2 im still using uiautomator1 how do i upgrade to v2
Tany_S
July 16, 2018, 11:32am
2
for appium 1.7.2 you have to use absolute co-ordinates.
below code works for me, hope will help u
public void swipeRightToLeft() {
Dimension size = webDriver.manage().window().getSize();
int startx = (int) (size.width *0.94);
int endx = (int) (size.width *0.24);
int starty = size.height / 2;
int finalendx = startx-endx;
int endy = 0;
(new TouchAction(webDriver)).press(point(startx,starty)).moveTo(point(-finalendx,endy)).release().perform();
}
Tany_S:
TouchAction
Thanks for ur code but im getting error could u please help me out
should i declare it, even the driver im getting error.
add this in ChooseDeliveryLocationPage :
import static io.appium.java_client.touch.offset.PointOption.point;
Also refer this for dealing with touch actions related issues:
having:
MobileElement myElement;
int xPoint, int yPoint;
int duration = XXXX; //in miliseconds
Tap on Element:
new TouchAction(localdriver).tap(tapOptions().withElement(element(myElement))).perform();
Tap on Coordinates:
new TouchAction(localdriver).tap(point(xPoint, yPoint)).perform();
Tap on Element using coordinates relative to element:
new TouchAction(localdriver).tap(tapOptions().withElement(element(myElement, xPoint, yPoint))).perform();
LongPress on Element:
new TouchAction(local…
public boolean swipeImages()
{
try
{
WebElement pageIndicator = driver.findElement(page_indicator);
String pageString= pageIndicator.getAttribute(“value”);
int length = pageString.length();
String count_string= pageString.substring(length-2, length).trim();
int count = Integer.parseInt(count_string);
for (int i=1; i<=count; i++){
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "right");
js.executeScript("mobile: scroll", scrollObject);
}
System.out.println("Swipe Successfully");
}
catch (Exception e)
{
System.out.println("Image Swipe was not successful.");
}
Thanks a lot for ur reply im not able to import…im using java-client 5.0.4
Thanks for ur reply in not able to understand what does page_indicator do i have put resource id and in text have given in getattribute im getting erro
Thanks all for ur suggestions because of u guys life becomes beautiful;) im trying to swipe from right to left
…i have a deadline to meet but because of this im stuck…after installation i need to swipe it…kindly help
Appium client - 5.0.4
Have i mentioned appium 1.7.2 and java-client 5.0.4 i do not want to upgrade it is it ok to use these versions
Hey, can you provide the UI Automator view for carousel …
Thanks!!
Hi harshitij
im getting this following error
i have upgraded to 6.1.0 java client that error went but im getting press error
Hi @Rathan_G ,
Above line of code is incorrect.The constructor of TouchAction is only accept driver as parameter.
Incorrect:
TouchAction action =new TouchAction(getDriver().press(point(startx,starty))…)
Correct:
TouchAction action =new TouchAction(getDriver()).press(point(startx,starty)).moveTo. …
or
TouchAction action =new TouchAction(getDriver());
action.press(point(startx,starty)).moveTo. …
Tany_S
July 18, 2018, 3:54pm
16
if u are using java client 5.0.4 you can use below code
public void swipeRightToLeft() {
Dimension size = webDriver.manage().window().getSize();
int startx = (int) (size.width *0.94);
int endx = (int) (size.width *0.24);
int starty = size.height / 2;
int finalendx = startx-endx;
int endy = 0;
(new TouchAction(webDriver)).press(startx,starty).moveTo(-finalendx,endy).release().perform();
}
Hi Tany,
im not getting error but horizontal swipe from right to left does not happen, press point works for 6.0v…kindly suggest im stuck.
appium 1.7.2
java-client : 6.0.0-BETA5
public void swipeRightToLeft() {
//getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Dimension size = getDriver().manage().window().getSize();
System.out.println(size);
int startx = (int) (size.width *0.94);
int endx = (int) (size.width *0.24);
int starty = size.height / 2;
int finalendx = startx-endx;
int endy = 0;
TouchAction actions = new TouchAction(getDriver());
actions.press(point(startx,starty)).waitAction(waitOptions(Duration.ofMillis(2000))).moveTo(point(finalendx, endy)).release().perform();
}
Tany_S
July 20, 2018, 12:43pm
18
@Rathan_G if you are using appium 1.7.2 and java client 6.0.0 beta5, u have to use absolute coordinates for 1.7.2
public void swipeRightToLeft() {
//getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Dimension size = getDriver().manage().window().getSize();
System.out.println(size);
int startx = (int) (size.width *0.94);
int endx = (int) (size.width *0.24);
int starty = size.height / 2;
int finalendx = startx-endx;
int endy = 0;
TouchAction actions = new TouchAction(getDriver());
actions.press(point(startx,starty)).waitAction(waitOptions(Duration.ofMillis(2000))).moveTo(point(-finalendx,endy)).release().perform();
}
if you use above code you may need to import below lines.
import java.time.Duration;
import static io.appium.java_client.touch.offset.PointOption.point;
import static io.appium.java_client.touch.WaitOptions.waitOptions;
Thanks for ur reply i updated from 5.0.4 to 6.0 because of press(point) not being compatible if it has to be actual co-ordinates will it affect different device size while running it…can u post an actual co-ordinates code…i really need to fix it fast …really appreciate it.
does it have anything to do with ui automator2? because im using uiautomator1