Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用appium在android应用程序中滚动表单_Android_Appium - Fatal编程技术网

如何使用appium在android应用程序中滚动表单

如何使用appium在android应用程序中滚动表单,android,appium,Android,Appium,我正在测试android应用程序 我可以将表格填写到设备上可见的某些字段 但现在我想滚动表单,填写其他字段,并点击最后一个按钮提交 我被困在这里,请帮帮我 只需将所有内容包装在一个滚动视图中即可: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_p

我正在测试android应用程序

  • 我可以将表格填写到设备上可见的某些字段
  • 但现在我想滚动表单,填写其他字段,并点击最后一个按钮提交

  • 我被困在这里,请帮帮我

    只需将所有内容包装在一个
    滚动视图中即可:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <!-- Here you put the rest of your current view-->
    </ScrollView>
    
    
    
    ScrollView只能包含一个项(作为子项只能包含一个布局)。。。所以如果你有这样的东西:

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <!-- bla bla bla-->
    </LinearLayout>
    
    
    
    您必须将其更改为:

    <ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
            <!-- bla bla bla-->
        </LinearLayout>
    </ScrollView>
    
    
    
    你可以参考一下

    或者简单的滚动视图示例


    只需将所有内容包装在
    滚动视图中即可:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <!-- Here you put the rest of your current view-->
    </ScrollView>
    
    
    
    ScrollView只能包含一个项(作为子项只能包含一个布局)。。。所以如果你有这样的东西:

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <!-- bla bla bla-->
    </LinearLayout>
    
    
    
    您必须将其更改为:

    <ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
            <!-- bla bla bla-->
        </LinearLayout>
    </ScrollView>
    
    
    
    你可以参考一下

    或者简单的滚动视图示例


    使用appium测试应用程序时,请使用以下代码垂直滑动:

    Dimension size = driver.manage().window().getSize(); 
    int starty = (int) (size.height * 0.80); 
    //Find endy point which is at top side of screen. 
    int endy = (int) (size.height * 0.20);
    //int endy = (int) (size.height * 0.10);
    //Find horizontal point where you wants to swipe. It is in middle of screen width. 
    int startx = size.width / 2; 
    
    //Swipe from Bottom to Top. 
    driver.swipe(startx, starty, startx, endy, 3000); 
    
    这将垂直向下滑动屏幕

    您也可以尝试使用此行滚动:

    // Scroll till element which contains Tabs text.
    driver.scrollTo("Tabs");
    
    当您面对android驱动程序时,请按如下方式声明:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName","fevicename");
    capabilities.setCapability("platformName","Android");
    //add more according to your requirement
    public AppiumDriver<WebElement> driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    
    DesiredCapabilities=新的DesiredCapabilities();
    能力。设置能力(“deviceName”、“fevicename”);
    能力。设置能力(“平台名”、“安卓”);
    //根据您的要求添加更多
    公共AppiumDriver驱动程序=新的AndroidDriver(新URL(“http://127.0.0.1:4723/wd/hub(能力),;
    
    使用appium测试应用程序时,请使用以下代码垂直滑动:

    Dimension size = driver.manage().window().getSize(); 
    int starty = (int) (size.height * 0.80); 
    //Find endy point which is at top side of screen. 
    int endy = (int) (size.height * 0.20);
    //int endy = (int) (size.height * 0.10);
    //Find horizontal point where you wants to swipe. It is in middle of screen width. 
    int startx = size.width / 2; 
    
    //Swipe from Bottom to Top. 
    driver.swipe(startx, starty, startx, endy, 3000); 
    
    这将垂直向下滑动屏幕

    您也可以尝试使用此行滚动:

    // Scroll till element which contains Tabs text.
    driver.scrollTo("Tabs");
    
    当您面对android驱动程序时,请按如下方式声明:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName","fevicename");
    capabilities.setCapability("platformName","Android");
    //add more according to your requirement
    public AppiumDriver<WebElement> driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    
    DesiredCapabilities=新的DesiredCapabilities();
    能力。设置能力(“deviceName”、“fevicename”);
    能力。设置能力(“平台名”、“安卓”);
    //根据您的要求添加更多
    公共AppiumDriver驱动程序=新的AndroidDriver(新URL(“http://127.0.0.1:4723/wd/hub(能力),;
    
    不再是

    在java client 4.0版本中,不推荐使用scrollTo和scrollToExact。 您必须使用
    driver.swipe()

    不再是

    在java client 4.0版本中,不推荐使用scrollTo和scrollToExact。
    您必须使用
    driver.swipe()

    我的示例来自python,但它也适用于Java,只需使用Java语法查找类似

    driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("**/Put some text of scroll screen/**").instance(0))')
    
    或者使用java语法

    driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"**/Put some text of scroll screen/**\").instance(0))")
    

    我的示例来自python,但也适用于Java,只要使用Java语法查找类似

    driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("**/Put some text of scroll screen/**").instance(0))')
    
    或者使用java语法

    driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"**/Put some text of scroll screen/**\").instance(0))")
    

    //创建一个方法名scrollTo或您选择的任何名称,使用下面提到的代码,它将获取要滚动的文本参数:

    public void scrollTo(String text){                
          driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+text+"\").instance(0))");
       }
    

    //创建一个方法名scrollTo或您选择的任何名称,使用下面提到的代码,它将获取要滚动的文本参数:

    public void scrollTo(String text){                
          driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+text+"\").instance(0))");
       }
    

    我写了一个代码用方向刷表单,它对我有用,这对你有帮助

    下面是上下滑动的代码

    if (Direction.equalsIgnoreCase("Up")) {
                startX = size.width / 2;
                startY = ((int) (size.height * 0.80) - Offset);
                endX   = startX;
                endY   = (int) (size.height * 0.20);
            }
            //down
            else if(Direction.equalsIgnoreCase("down")) {
                startX = size.width / 2;
                startY = ((int) (size.height * 0.20) + Offset);
                endX   = startX;
                endY   = (int) (size.height * 0.80);
            }
    
    pointOption = new PointOption();
    
    new TouchAction<>(getDriver()).press(pointOption.point(startX, startY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
                    .moveTo(pointOption.point(endX, endY)).release().perform();
    
    if(Direction.equalsIgnoreCase(“Up”)){
    startX=尺寸。宽度/2;
    星形=((内部)(尺寸高度*0.80)-偏移);
    endX=startX;
    endY=(int)(大小、高度*0.20);
    }
    //向下
    else if(方向等信号(“向下”)){
    startX=尺寸。宽度/2;
    星形=((内部)(尺寸高度*0.20)+偏移量);
    endX=startX;
    endY=(int)(大小、高度*0.80);
    }
    pointOption=新的pointOption();
    新建TouchAction(getDriver())。按(pointOption.point(startX,startY)).waitAction(WaitOptions.WaitOptions(Duration.ofMillis(1000)))
    .moveTo(pointOption.point(endX,endY)).release().perform();
    
    我写了一个代码,可以用方向键滑动表单,这对我很有用,这对你很有帮助

    下面是上下滑动的代码

    if (Direction.equalsIgnoreCase("Up")) {
                startX = size.width / 2;
                startY = ((int) (size.height * 0.80) - Offset);
                endX   = startX;
                endY   = (int) (size.height * 0.20);
            }
            //down
            else if(Direction.equalsIgnoreCase("down")) {
                startX = size.width / 2;
                startY = ((int) (size.height * 0.20) + Offset);
                endX   = startX;
                endY   = (int) (size.height * 0.80);
            }
    
    pointOption = new PointOption();
    
    new TouchAction<>(getDriver()).press(pointOption.point(startX, startY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
                    .moveTo(pointOption.point(endX, endY)).release().perform();
    
    if(Direction.equalsIgnoreCase(“Up”)){
    startX=尺寸。宽度/2;
    星形=((内部)(尺寸高度*0.80)-偏移);
    endX=startX;
    endY=(int)(大小、高度*0.20);
    }
    //向下
    else if(方向等信号(“向下”)){
    startX=尺寸。宽度/2;
    星形=((内部)(尺寸高度*0.20)+偏移量);
    endX=startX;
    endY=(int)(大小、高度*0.80);
    }
    pointOption=新的pointOption();
    新建TouchAction(getDriver())。按(pointOption.point(startX,startY)).waitAction(WaitOptions.WaitOptions(Duration.ofMillis(1000)))
    .moveTo(pointOption.point(endX,endY)).release().perform();
    

    其显示错误//类型WebDrivers的方法scrollTo(String)未定义。如何声明应用程序驱动程序?在此处给出声明公共类GoldenGate{WebDriver driver;现在我正在尝试使用AndroidDriver驱动程序;让我们看看现在我遇到了错误对于类型AndroidDriverits,方法scrollTo(String)是未定义的,显示错误//方法scrollTo(String)类型WebDrivers未定义,那么如何声明应用程序驱动程序?请在此声明公共类GoldenGate{WebDriver driver;现在我正在尝试使用AndroidDriver驱动程序;让我们看看现在我得到的错误方法scrollTo(字符串)未定义类型AndroidDriverPlease提供代码。到目前为止您尝试了什么?输入代码,请检查如何提问,规则:我们不为您编码。请提供代码。到目前为止您尝试了什么?输入代码,请检查如何提问,规则:我们不为您编码。提问者不需要拖放元素需要滚动他的表单。还有你是如何获得id的!!!!!好的,我很抱歉我误解了它。你说得对..谢谢。我会编辑我的答案提问者不需要拖放元素。。