1

I am trying to take screen shot of the web page showing the tool tip text, but I can only see WebElement text being highlighted after mouse hover, but tool tip is not even shown up on the web page during script execution.

Here is the piece of code, that I am trying to execute. Need help to figure out what am I missing..

 public static void main(String[] args) throws InterruptedException, IOException, AWTException  
   {
    String URL = "https://www.rediff.com";
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\bhara\\eclipse-workspace\\Drivers\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get(URL);
    driver.manage().window().maximize();
    driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);

    String WebElementXpath = "//*[@class='mailicon']";

    String toolTipText ;
    WebElement ToolTipElement = driver.findElement(By.xpath(WebElementXpath));

    Actions act1 = new Actions(driver);


    act1.moveToElement(ToolTipElement).build().perform();

     Robot robot = new Robot();

     Point point;
     point = ToolTipElement.getLocation();
     int x = point.getX(); 
     int y = point.getY(); 
     robot.mouseMove(x,y);

     File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
     FileUtils.copyFile(scrFile, new File("screenshot.png"));

    System.out.println( ToolTipElement.getAttribute("title"));

}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Perhaps you just need to add a delay ? Tooltips never appear instantly – Marged Dec 03 '19 at 05:57
  • HI, Thanks for the response! I added Thread.sleep(3000) before taking screen shot. I still did not get to see tooltip text on the webpage. – user11762715 Dec 03 '19 at 06:07

1 Answers1

1

I don't see any such issues in your code block as such. However if you observe the HTML DOM of the WebElement:

title

The text Lightning fast free email is the title attribute but not the tooltip as such. Hence through using Actions class to Mouse Hover over the element won't bring up the popup. However, I made some small changes and executed you code to get the same result as follows:

  • Code Block:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
    options.setExperimentalOption("useAutomationExtension", false);
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://www.rediff.com/");
    new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@class='mailicon']")))).build().perform();
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scrFile, new File(".\\Screenshots\\Rediffmail.png"));
    System.out.println(driver.findElement(By.xpath("//a[@class='mailicon']")).getAttribute("title"));
    driver.quit();
    
  • Console Output:

    Lightning fast free email
    
  • Screenshot:

Rediffmail.png

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the response. Is there way to have the tool tip text to come up on screen while running the screen, as it does when we manually mouse hover on and see the tool tip? – user11762715 Dec 04 '19 at 03:49