title: Compare two HTML sources and display visual differences
body: <p>I am trying to show where the two HTML pages differ. I am trying to figure out a way if i can compare the HTML source code of two webpages(almost similar), and show/highlight the differences visually(on UI).</p>
  
  <p><strong>What I tried:</strong> I thought of taking snapshot of the page and then use <a href="http://huddle.github.io/Resemble.js/">Resemble.js</a> to compare two images. But that shows very minute differences as well and results are something which is not clear.</p>
  
  <p>I thought of comparing the DOM structure or the source code and then show what or where actually the two pages differ on <strong>UI</strong>.</p>
  
  <p>Is there any way i could achieve this?  I am using <a href="https://code.google.com/p/selenium/">Selenium- Webdriver</a> to get the snapshots and the HTML source code.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I guess my question was not clear. Actually, i wanted to find out the difference in HTML content for webpages in order to detect A/B tests being performed currently. I first grabbed the html source into a text file and then compared it with previously captured HTML source using <a href="https://code.google.com/p/java-diff-utils/">Java-Diff util</a> . This gave me the actual lines which differ in two text files with HTML source.</p>
  
  <p>Now, the problem is, how can i show this difference on UI as in highlighting the areas which i found are different? Hope this would make it more clear.</p>
  
  <p>The below code shows the lines which differ</p>
  
  <pre><code>List&lt;String&gt; original = fileToLines("HTML Source diff/originalSource.txt");
      List&lt;String&gt; revised = fileToLines("HTML Source diff/sourceAfterCookieClear.txt");
  
      // Compute diff. Get the Patch object. Patch is the container for computed deltas.
      Patch patch = DiffUtils.diff(original, revised);
  
      System.out.println("Printing Deltas\n");
      for (Delta delta : patch.getDeltas()) {
          String revisedText = delta.getRevised().toString();
          String content = revisedText.substring(revisedText.indexOf(" [")+2,revisedText.indexOf("]]"));
          writeTextToFile(content,"difference.html");
      }
  </code></pre>
  
  <p>Any leads in form of code would be helpful. </p>