아마존의 쇼핑 앱에서 테스트되었습니다. 스 와이프 한 후 요소를 찾기 위해 문제가 있습니다. 목록보기가 너무 길기 때문에 스크롤해야합니다 (스 와이프 API 사용). 하지만 스 와이프 한 후에는 더 이상 요소를 클릭 할 수 없습니다. 그것은 오류를 반환하지 않았지만 응용 프로그램은 응답이 없습니다.앱스에서 스 와이프 한 후 요소를 클릭 할 수 없습니다.
함수 ScrollToElement()는 검색 요소로 스 와이프합니다. 나는 터치 액션 탭을 사용하려고했지만 희망이 없다. 정확한 (372,466) 위치를 탭하려했으나 제대로 작동하지만 예상대로 아닙니다. 미리 감사드립니다.
public class FirstTest {
private AppiumDriver driver;
private Dimension size;
@BeforeClass
public void Setup() throws MalformedURLException {
String appActivityText = "com.amazon.mShop.home.HomeActivity";
String appPackageText = "in.amazon.mShop.android.shopping";
String fileLocation = "/system/app/";
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "\\STC");
File app = new File(appDir, fileLocation);
System.out.println(app);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.PLATFORM, "Android");
capabilities.setCapability(CapabilityType.VERSION, "4.4.2");
capabilities.setCapability("deviceName", "420373d0de528100");//420373d0de528100 01a61316598f30e6
capabilities.setCapability("newCommandTimeout", "100");
// capabilities.setCapability("app", "Chrome"/*app.getAbsolutePath()*/);
capabilities.setCapability("appPackage", appPackageText);
capabilities.setCapability("appActivity", appActivityText);
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
@Test
public void Login() throws Exception {
// Click on Shop by Deparment link
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
System.out.println("Click on Shop by Deparment link");
driver.findElement(By.id("web_home_shop_by_department_label")).click();
Thread.sleep(1000);
WebElement element = driver.findElement(By.name("Office Products Link"));
ScrollToElement(driver, element);
Thread.sleep(3000);
// TouchAction action = new TouchAction(driver);
// action.tap(372,466).perform();
driver.findElement(By.name("Office Products Link")).click();
}
@AfterClass
public void closeApp() {
// driver.closeApp();
}
public static void ScrollToElement(AppiumDriver driver, WebElement element){
size = driver.manage().window().getSize();
// Find swipe start and end point from screen's with and height.
// Find starty point which is at bottom side of screen.
int start = (int) (size.height * 0.20);
int starty = (int) (size.height * 0.80);
// Find endy point which is at top side of screen.
int endy = (int) (size.height * 0.20);
// Find horizontal point where you wants to swipe. It is in middle of
// screen width.
int startx = size.width/2;
while (true) {
driver.swipe(startx, starty, startx, endy, 3000);
start = start + (starty - endy);
if (element.getLocation().getY() - start < size.height - endy) {
break;
}
}
}
}
실제로. 내가 찾고자하는 요소는 이미 표시되어 있지만 목록보기의 맨 아래에 있습니다. API getsize(), driver.findElement (By.name ("Office Products Link")). getsize()를 사용합니다. 값을 반환했습니다. 하지만 요소를 클릭 할 수 없습니다. 그 때문에 요소를 나타 내기 위해 화면을 스크롤하려고했습니다. 이것에 대해서는 잘 모르겠지만 도움을 주셔서 감사합니다 – Stephen
요소가 화면 하단에있는 경우 요소를 찾은 후에 다른 스크롤을 수행해야합니다. 당신이 할 수있는 것은 -'starty = ... * 0.6'과'endy = ... * 0.4'를 가진'slowScroll()'입니다.이 스크롤 후에 아이템은 화면 중앙에 있습니다 - 클릭 할 준비가되었습니다. . 좌표를 사용하여 요소의 상단 부분에서 tap()을 수행 할 수도 있습니다. 그러나 먼저 이것을 시도해 봅시다. –
David에게 감사하지만, 나는 appium을 가진 초보자입니다. "좌표를 사용하여 요소의 상단 부분에서 tap()을 수행합니다."그것은 무엇을 의미합니까? 나를 안내 해줄 수 있니? – Stephen