Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Selenium 当尝试从下到上滑动屏幕直到页面结束时,但在appium中没有发生滑动_Selenium_Appium - Fatal编程技术网

Selenium 当尝试从下到上滑动屏幕直到页面结束时,但在appium中没有发生滑动

Selenium 当尝试从下到上滑动屏幕直到页面结束时,但在appium中没有发生滑动,selenium,appium,Selenium,Appium,我试图使用touch action类使用swipe查找元素,但Appium服务器抛出一个错误,即命令有问题。我试图使用touch action类使用坐标从一个位置移动到另一个位置。我的代码如下所示: @Test(priority=4) public void selectprod() { drivertest.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS); WebElement categ= drivertest

我试图使用touch action类使用swipe查找元素,但Appium服务器抛出一个错误,即命令有问题。我试图使用touch action类使用坐标从一个位置移动到另一个位置。我的代码如下所示:

 @Test(priority=4)
 public void selectprod()
 {

drivertest.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
     WebElement categ= drivertest.findElementsByName("See All").get(1);
    categ.click();

        TouchAction abc=new TouchAction(drivertest);
        abc.longPress(479, 754).moveTo(0, -500).perform();

            if (drivertest.findElement(By.name("Pragnya Manufacturer")).isDisplayed())
            {
                drivertest.findElement(By.name("Pragnya Manufacturer")).click();

            }
       }
服务器正在抛出此错误,如下所示:

 @Test(priority=4)
 public void selectprod()
 {

drivertest.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
     WebElement categ= drivertest.findElementsByName("See All").get(1);
    categ.click();

        TouchAction abc=new TouchAction(drivertest);
        abc.longPress(479, 754).moveTo(0, -500).perform();

            if (drivertest.findElement(By.name("Pragnya Manufacturer")).isDisplayed())
            {
                drivertest.findElement(By.name("Pragnya Manufacturer")).click();

            }
       }
服务器没有响应错误


我可以马上告诉您有4项改进:

  • 最重要的是,尽量不要使用隐式等待

    WebDriverWait wait = new WebDriverWait(driver, 60); //60 is the wait time in seconds
    wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    
  • 请使用此代码块进行滚动,将
    starty
    endy
    更改为更改滚动长度和方向

    public void scrollDown() 
    {
        Dimension size = driver.manage().window().getSize();
        int starty = (int) (size.height * 0.7);
        int endy = (int) (size.height * 0.2);
        int startx = size.width / 2;
        driver.swipe(startx, starty, startx, endy, 800);
    }
    
  • 如果元素不可见,函数
    isDisplayed()
    将引发异常,请用
    try
    catch
    将其包围

  • 您只需滚动一次,可能元素位于表中较低的位置,我建议您进行
    for()
    循环(不要忘记为滚动迭代添加限制)

  • 公共静态无效swipeLeft(AppiumDriver驱动程序)
    {
    维度大小=driver.manage().window().getSize();
    int startx=(int)(尺寸宽度*0.8);
    int endx=(int)(size.width*0.16);
    整型星形=(整型)(尺寸高度*0.75);
    驱动程序。轻扫(startx、starty、endx、starty、1000);
    }
    
    希望这会有所帮助