1
我在亞馬遜購物應用上測試過。輕掃後找到一個元素,我有一個問題。 因爲列表視圖太長。我需要滾動(使用滑動API)。但是在滑動後,我無法再點擊該元素。它沒有返回任何錯誤,但應用程序沒有響應。在appium中刷卡後無法點擊元素
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
如果元素位於屏幕的底部,那麼您需要在找到元素後再進行一次滾動。你可以做的是 - 'slowScroll()',其中'starty = ... * 0.6'和'endy = ... * 0.4'。這個滾動項目將在屏幕中間 - 準備點擊。 您還可以使用其座標在元素的頂部執行tap()。但首先讓我們試試這個。 –
謝謝大衛,但我是一個有appium的新手。 「使用座標」在元素的頂部執行tap()「是什麼意思?你能指導我嗎? – Stephen