title: How to select a number of words from a Paragraph ? (Selenium)
body: <p>The Webpage consists of a list of paragraphs and When the user clicks the button, the Selected words should copy from that paragraph.</p>
  <p>How to achieve this through Selenium.?</p>
  <p>I wrote javascript code but it is not selecting the words.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>String script = "var range = document.createRange();" +
  "var start = document.getElementsClassname('COTX1');" +
  "var textNode = start.getElementsByTagName('p')[0].firstChild;" +
  "range.setStart(textNode, 8);" +
  "range.setEnd(textNode, 13);" +
  "window.getSelection().addRange(range);";
   ((JavascriptExecutor)driver).executeScript(script);</code></pre>
  </div>
  </div>
  </p>
  <p>e.g. in the below paragraph: I want to select the words starting from <strong>early</strong> till <strong>more economically viable.</strong></p>
  <pre><code>&lt;p class=&quot;COTX1&quot;&gt;&lt;span class=&quot;CO_DC&quot;&gt;A&lt;/span&gt;s early as 1619, white Americans imported enslaved Africans to the New World with the idea of making agricultural enterprises such as tobacco growing more economically viable. Though most Americans considered it morally wrong, slavery persisted as part of the economic engine that European settlements built on these shores. The Founding Fathers knew that slavery violated the republic’s democratic principles, yet the constitutional debates of 1787–88 show that if it had been outlawed, some colonies would never have joined the union.&lt;/p&gt;
  </code></pre>