indent preformatted text by 4 spaces@Test
public void ChangePass(int startX, int startY, int endX, int endY, int duration) throws InterruptedException {
WebDriverWait wait = new WebDriverWait(driver, 25);
wait.until(ExpectedConditions.elementToBeClickable(By.id(myprofile)));
//Click the profile icon
driver.findElement(By.id(myprofile)).click();
//Click the sign in button
driver.findElement(By.id(sign)).click();
//Enter Username
driver.findElement(By.id(enterUsernameButton)).sendKeys("[email protected]");
//Enter Password
driver.findElement(By.id(enterPasswordButton)).sendKeys("Soni2017");
//Tap the DONE button
driver.findElement(By.id(signUpDoneButton)).click();
wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.id(myprofile)));
driver.findElement(By.id(myprofile)).click();
driver.findElement(By.id(name)).click();
if (!driver.findElements(By.id(editprofile)).isEmpty()) {
Thread.sleep(1000);
driver.findElement(By.id(editprofile)).click();
} else {
Thread.sleep(2000);
driver.findElement(By.xpath(ediProfile)).click();
}
//Enter the code for "Edit Profile"
//Insert a code that scrolls down to the bottom of the screen
// Scroll down
// X[63,904]
// Y[365,9771
new TouchAction((MobileDriver) driver).press(startX, startY).waitAction(Duration.ofMillis(5000)).moveTo(endX, endY).release().perform();
//Change Password button
driver.findElement(By.id(changePassword)).click();
After adding in your example it gave me an error saying:
java.lang.Exception: Method ChangePass should have no parameters
I was trying out your code. Initially it will open Settings App in IOS and execute below code. But it is not scrolling to “Battery” option.
public boolean scrollToDirection_iOS_XCTest() {
MobileElement el = (MobileElement)aDriver.findElement(By.xpath("//*[@value='Battery']"));
String direction = "d";
// The main difference from swipe call with the same argument is that scroll will try to move
// the current viewport exactly to the next/previous page (the term "page" means the content,
// which fits into a single device screen)
try {
JavascriptExecutor js = (JavascriptExecutor) aDriver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
if (direction.equals("d")) {
scrollObject.put("direction", "down");
} else if (direction.equals("u")) {
scrollObject.put("direction", "up");
} else if (direction.equals("l")) {
scrollObject.put("direction", "left");
} else if (direction.equals("r")) {
scrollObject.put("direction", "right");
}
scrollObject.put("element", el.getId());
scrollObject.put("toVisible", "true"); // optional but needed sometimes
js.executeScript("mobile:scroll", scrollObject);
return true;
} catch (Exception e) {
return false;
}
}
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?
Yes, using latest stable build 5.0.4 as ochubey said. Trying this on a real Samsung S5 with 1080x1920 screen size— also same issue on Nexus 6. Also using Java JDK 8 and selenium 3.9.1. Testing on native android app.
The strange thing is it actually swiped ok one time, very very slowly (maybe over 10 seconds even though duration was set to 2 seconds). After that, it keeps erroring with subsequent runs, even with fresh restart of appium and clearing the app’s cache.
I’ve just tried this on the native Google Play Store app and it’s working as expected, so it could be an issue with the apk I am testing, as it is an older version.
Hi, i have used the below code to Swipe / Scroll and it is working perfectly.
Code to Swipe UP
public boolean swipeFromUpToBottom()
{
try {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put(“direction”, “up”);
js.executeScript(“mobile: scroll”, scrollObject);
System.out.println(“Swipe up was Successfully done.”);
}
catch (Exception e)
{
System.out.println(“swipe up was not successfull”);
}
return false;
}
Code to Swipe DOWN
public boolean swipeFromBottomToUp()
{
try {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put(“direction”, “down”);
js.executeScript(“mobile: scroll”, scrollObject);
System.out.println(“Swipe down was Successfully done”);
}
catch (Exception e)
{
System.out.println(“swipe down was not successfull”);
}
return false;
}
@VikramVI it’s make my day but i can’t understand Code new TouchAction(driver).press(115, 650).waitAction(ofSeconds(1)).moveTo(115, 350).release().perform(); In Press you have to passed (115,650) what does That mean ? And In Move to You have to Pass (115,350) What does that mean ? How to measure Co-ordinate I don’t Know. Can You Please explain How to Measure Co-ordinate in Mobile ?