scrollDownTillElement

    0

    1

    Yogesh Wankhede

    This code verifies that a toast message with the given content is present on the current page. The code loops through all the string resources contained in the current page and checks to see if the given toast message is present. If it is, the code sets a flag to indicate that the toast message was found. The code then sleeps for 300 milliseconds to ensure that the toast message is present on the page for a longer period of time.

    Library: selenium

    
    public static void scrollDownTillElement(String xPath, AppiumDriver driver) {
      boolean flag=true;
      int count=1;
      while(flag){
        try {
          driver.findElement(By.xpath(xPath));
          flag=false;
          break;
        }
        catch(Exception NoSuchElementException) {
          count=count+1;
          Map<String, Object> params = new HashMap<>();
          params.put("start","40%,90%");
          params.put("end","40%,20%");
          params.put("duration","2");
          Object res= driver.executeScript("mobile:touch:swipe",params);
        if(count==5)
        {
          break;
        }
        }
      }
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.