/*
* How to find the highlighed text on webpage.
* Programming language : JAVA
 * Autoamtion Library : Selenium
*
* We can achieve this with the help of JavaScript window.getSelection().toString() function
*
*/
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;



public class HighlightedTextOnWebPage {

public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = null;

driver.get("https://google.com");
Thread.sleep(5000);
// Try to highlight any text on webpage using the mouse.


if (driver instanceof JavascriptExecutor) {
js = (JavascriptExecutor)driver;
}

String hldText = (String)js.executeScript("return window.getSelection().toString();");
System.out.println("Highlighted Text on WebPage is : " + hldText.trim());

}
}