title: How to use swipe function using selenium
body: <p>I have to swipe through some articles using article id, But after every 4 articles  swipe there is a one ad, How can i manage it. and also I have to print the name of the article too. I used following code</p>
  
  <pre><code>    ...
      System.out.println(driver.manage().window().getSize().getWidth());
      System.out.println(driver.manage().window().getSize().getHeight());
  
      int screenWidth = driver.manage().window().getSize().getWidth();
      int screenHeight = driver.manage().window().getSize().getHeight();
      try {
          element = driver.findElements(By.id("templeconnect.com.templeconnect:id/templetitle"));
      } catch (NoSuchElementException e) {
          System.out.println("no such element");
      }
  
      //swipe up
      startx = screenWidth / 2;
      endx = screenWidth / 2;
      starty = screenHeight * 6 / 7;
      endy = screenHeight / 7;
      driver.swipe(startx, starty, endx, endy, 2000);
      Thread.sleep(3000);
      myfun(element);
  
  }
  
  public void myfun(List&lt;WebElement&gt; element) {
      try {
          System.out.println(element.size());
          for (WebElement webElement : element) {
              System.out.println(webElement.getText());
              if (webElement.getText().equals("")) {
              } else {
                  driver.swipe(startx, starty, endx, endy, 2000);
                  Thread.sleep(3000);
                  myfun(element);
              }
          }
      } catch (NoSuchElementException e) {
          System.out.println("no such element my funtion");
      } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  
  public void myfun1(List&lt;WebElement&gt; element1) throws InterruptedException {
      for (WebElement webElement1 : element1) {
          System.out.println(webElement1.getText());
          if (webElement1.getText().equals("EXPLORE MORE")) {
              driver.swipe(startx, starty, endx, endy, 2000);
          }
      }
  }
  </code></pre>