我需要执行大量的帐户关闭。可以在屏幕上一次显示200个帐户的列表,这些帐户可以作为下拉列表使用。仅6个帐户,其他人需要向下滚动。如何执行它使用Appium脚本。我试过的流程和我试过的示例源代码如下所示
package ******;
import java.util.List;
import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidElement;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class QuickPay extend ********{
@Test
public void T1a_Landingpage() {
public void scroll(int i){
do{
size = driver.manage().window().getSize(); //Get the size of screen.
System.out.println(size);
int starty = (int) (size.height * 0.80);//Find starty point which is at bottom side of screen.
int endy = (int) (size.height * 0.20); //Find endy point which is at top side of screen.
int startx = size.width / 2; //Find horizontal point where you wants to swipe. It is in middle of screen width.
System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx); // int startx = size.width;
driver.swipe(startx, starty, startx, endy, 3000);//Swipe from Bottom to Top.
//Thread.sleep(2000);
}
//AAD Closing starts
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-button-1')]")).sendKeys("1111");
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-tab-5')]")).click();
for(int i=1;i<10;i++){
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-button-18')]")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-input-5')]")).click();
do{
if (driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-simplelistitem-"+i+"')]")) != null){
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-simplelistitem-"+i+"')]")).click();
}
else{
scroll(i);
}i++;
}
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-simplelistitem-"+i+"')]")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-input-6')]")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-simplelistitem-3')]")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-button-30')]")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-button-31')]")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-button-37') and @index='1']")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-button-37') and @index='1']")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-button-37') and @index='1']")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-button-37') and @index='1']")).click();
driver.findElement(By.xpath("//android.view.View[contains(@resource-id,'ext-button-49')]")).click();
}
答案 0 :(得分:0)
如果您使用的是1.5以上的appium版本,则可以执行以下操作
Dimension size = driver.manage().window().getSize();
logger.info("size of screen" + size);
// Find swipe start and end point from screen's with and height.
// 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;
logger.info("Scrolling down with the coordinates " + "startx = " + startx + " ,endx = " + endx + " , starty = "
+ starty);
// Scroll down
driver.swipe(startx, starty, endx, starty, 3000);
注意:屏幕尺寸尺寸适用于iPad
否则如果使用1.6以下,则可以使用JavaScript滚动
答案 1 :(得分:0)
通常我会从屏幕上的第一个元素位置滑动到屏幕上第6个元素的位置,直到屏幕上的第一个元素与上一个迭代相似,如下面的代码所示
public boolean removeGroupByName() {
nameStart = "";
while (true) {
doYourLogicOnThe6Elements();
if (!keepSwippingGroup()) {
break;
}
}
return true;
}
private static String nameStart = "";
private boolean keepSwippingList() {
if (isElementPresent(By.xpath(FIRST_ELEMENT_XPATH)) && isElementPresent(By.xpath(LAST_ELEMENT_XPATH))) {
AndroidElement firstElement = (AndroidElement) driver.findElementByXPath(FIRST_ELEMENT_XPATH);
AndroidElement lastElement= (AndroidElement) driver.findElementByXPath(LAST_ELEMENT_XPATH);
if (nameStart.equals(firstElement.getText())) {
return false;
} else {
nameStart = firstElement.getText();
swipe(lastElement.getLocation().x, lastElement.getLocation().y, firstElement.getLocation().x,
firstElement.getLocation().y, 2000);
}
return true;
}
return false;
}