appium长按和移动元素(拖放)不起作用

时间:2016-03-18 12:26:43

标签: java appium appium-ios

我有一个方案来测试这样的IOS应用程序:

  
      
  1. 长按元素。
  2.   
  3. 将该元素移动到所需位置。
  4.   

我使用以下代码:

TouchAction action = new TouchAction(driver)
action.long_press(element1).move_to(element2).wait(500).release().perform()

但它不适合我。需要任何好的建议。

5 个答案:

答案 0 :(得分:12)

我也遇到了麻烦。但我解决了这个问题如下:

TouchAction action = new TouchAction(driver);
action.longPress(elem1).waitAction(3000).moveTo(elem2).perform().release();

waitAction将等待完成longPress操作而不是moveTo操作将执行。

答案 1 :(得分:1)

//You need to import following 
import org.openqa.selenium.WebElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.LongPressOptions;
import io.appium.java_client.touch.offset.ElementOption;

//first for the intial location to be long pressed
WebElement first= driver.findElementByXPath("//*[@content-desc='15']");

//second location on which you need to move to
WebElement second= driver.findElementByXPath("//*[@content-desc='45']");

TouchAction action = new TouchAction(driver);

//performing the long press
action.longPress(new LongPressOptions().withElement(new 
                       ElementOption().withElement(first))).perform();

//performing the move to touch operation
action.moveTo(new ElementOption().withElement(second)).perform();

答案 2 :(得分:0)

我发现没有一个longPress()组合可以工作,所以我得到了这个变种,你强迫它执行按下然后移动。在Android和iOS上测试过,似乎不适用于UWP

new TouchAction(driver)
    .press(PointOption.point(256, 1115))
    .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))
    .perform()
    .moveTo(PointOption.point(256, 600))
    .release()
    .perform();

答案 3 :(得分:0)

<块引用>

如果你已经有元素的引用,那么你会这样做:

TouchAction action = new TouchAction(driver);
        action.longPress(new ElementOption().withElement(first))
                .waitAction(WaitOptions.waitOptions(Duration.ofMillis(3000)))
                .moveTo(new ElementOption().withElement(last))
                .release()
                .perform();

答案 4 :(得分:-1)

library(dplyr)
df1 %>% 
  group_by(Team) %>% 
  mutate(Team_Count = sum(Shot_Count[!duplicated(Player_ID)]))
# A tibble: 6 x 5
# Groups: Team [2]
#  Player_ID Team  Shot_Count Date     Team_Count
#      <int> <chr>      <int> <chr>         <int>
#1         1 Red           14 12/15/12         37
#2         2 Blue          12 2/14/12          27
#3         3 Red           23 12/15/12         37
#4         4 Blue          15 3/15/12          27
#5         2 Blue          14 5/2/12           27
#6         3 Red           23 11/11/12         37