title: Can we retrieve text/drag n drop elements using JavascriptExecutor similarly we are doing with gettext/Actions in Selenium
body: <p>In below code if the my div containing the attribute as text then only it will return the text. I am new/curious to find new way to use JavascriptExecutor instead of selenium as they are much faster than selenium</p>
  
  <pre><code>WebElement gettexxxt= driver.findElement(By.id("loginButton"));
  JavascriptExecutor executor1 = (JavascriptExecutor) driver;
  String text = (String) executor1.executeScript("return arguments[0].text;", gettexxxt));
  System.out.println(text);
  </code></pre>
  
  <p>Right now I am retrieving the text as below using JavascriptExecutor</p>
  
  <pre><code>WebElement Rent_rentc =(WebElement) ((JavascriptExecutor) driver).executeScript("return document.getElementById('loginButton');");
  System.out.println(Rent_rentc.getText());
  </code></pre>
  
  <p>Is there any way to get text using JavascriptExecutor except above solution?</p>
  
  <p><strong>Note:- I am editing this question as I got the answer of how to gettext from JavascriptExecutor by referring Vicky answer in this page. Please refer from here to answer my next problem that how we can perform drag and drop using JavascriptExecutor.</strong> </p>
  
  <p>I am facing error in below code, Error :- <strong>No match found</strong></p>
  
  <pre><code>    driver.get("https://jqueryui.com/droppable/");
      WebElement iframe=driver.findElement(By.xpath(".//*[@id='content']/iframe"));
      driver.switchTo().frame(iframe);
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  
      try{  
        String filePath = "./dnd.js-master//dnd.js";
        String source = "div[id='draggable']";
        String target = "div[id='droppable']";
        StringBuffer buffer = new StringBuffer();
        String line;
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        while((line = br.readLine())!=null)
            buffer.append(line);
  
        Pattern pattern = Pattern.compile("'(.*?)'");
        Matcher matcherSource = pattern.matcher(source);
        Matcher matcherTarget = pattern.matcher(target);
        String cssSource = "#" + matcherSource.group(1);
        String cssTarget = "#" + matcherTarget.group(1);
  
        String javaScript = buffer.toString();
  
        javaScript = javaScript + "$('" + cssSource + "').simulateDragDrop({ dropTarget: '" + cssTarget + "'});";
        ((JavascriptExecutor)driver).executeScript(javaScript);
  
      }
      catch(Exception ex)
      {
          System.out.println(ex.getMessage());
      }
  </code></pre>
  
  <p>Another code error :- <strong>expected expression, got '.'</strong></p>
  
  <pre><code>    WebDriver driver = new FirefoxDriver();
      driver.manage().window().maximize();
      driver.get("https://jqueryui.com/droppable/");
       String line = null;
        String source = ".//*[@id='draggable']";
        String target = ".//*[@id='droppable']";
        try{
       BufferedReader br = new BufferedReader(new FileReader("./dnd.js-master//Drag.js"));
       StringBuffer buffer = new StringBuffer();
       while((line = br.readLine())!=null)
           buffer.append(line);
  
       String javaScript = buffer.toString();
  
       Thread.sleep(5000);//you can remove it added just to show you that drag and drop appeared as it is too fast
  
       String java_Script = javaScript + "$("+source+").simulateDragDrop({ dropTarget: "+target+"});";
  
       ((JavascriptExecutor)driver).executeScript(java_Script);
        }
              catch(Exception ex){
                  System.out.println(ex.getMessage());
        }
  </code></pre>
  
  <p>}</p>