1

I want to get text/value from the tooltip which appears when hover on svg element on the graph created with highcharts. Below is the snippet:

Highchart graph snippet

Tried below code:

List<WebElement> Volumelist=driver.findElements(By.xpath("//*[name()='svg']//*[name()='g'][5]//*[name()='g'][2]//*[name()='path']"));
System.out.println("Got the list!");        
new Actions(driver).moveToElement(Volumelist.get(1)).clickAndHold().build().perform();
WebElement toolTip=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class='highcharts-halo highcharts-color-3'][@visibility='visible']")));  
System.out.println("toolTip text= "+toolTip.getText());
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Please provide the HTML Source code after hovering over point you want to extract the information from. Usually, the tooltip is contained in a separate div lower in the HTML source. – sagarwadhwa1 Jul 18 '18 at 09:02
  • Check this discussion https://stackoverflow.com/questions/41829000/selenium-webdriver-java-how-to-click-on-elements-within-an-svg-using-xpath – undetected Selenium Jul 18 '18 at 09:03
  • @DebanjanB I think OP is having issues with locating the tooltip in the HTML source code and not with hovering on the point itself – sagarwadhwa1 Jul 18 '18 at 09:11
  • If you just want the actual values from the graph, you can just use a point event in highchart, see: http://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-point-events-mouseover/ Or even simpler: putting the values in console: http://jsfiddle.net/ewolden/tzugyx7L/1/ – ewolden Jul 18 '18 at 09:44

3 Answers3

1

First hover on the element on which tooltip appears and then execute :

String tooltipText = driver.findElement(By.cssSelector("g.highcharts-tooltip text tspan")).getAttribute("textContent");

You can ping me at sandpdangi13@gmail.com if that does not work for you.

Try to hover to tooltip element using this method if normal Actions hover is not working :

 public static void mouseHoverJScript(WebDriver driver, WebElement element) {
        String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false);"
                + " arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
        ((JavascriptExecutor) driver).executeScript(mouseOverScript,
                element);
dangi13
  • 1,275
  • 1
  • 8
  • 11
  • Tried this also but for Tooltip.getAttribute("textContent") it says element not found. I think hover is not working properly as I am able to locate tooltip & element on which tooltip appears with firepath. – Kalyani Kachhi Jul 19 '18 at 13:24
  • Thanks All for responses. I resolved hover issue with below code: new Actions(driver).moveToElement(elem).clickAndHold().moveByOffset(1, 1).pause(1000).perform(); – Kalyani Kachhi Jul 20 '18 at 10:40
0

I found over their examples page the values with this XPath:

driver.findElement(By.xpath(.//*[name()="g" and contains(@class,"highcharts-label")]//*[name()="tspan" and @style='font-weight:bold'])).getText();

The first step is move the mouse over one point, for example with this XPath, move to the first point:

WebElement elem = DriverUtils.driver.findElement(By.xpath(.//*[name()='path' and contains(@class, 'highcharts-point highcharts-color')][1]));
new Actions(driver).moveToElement(elem).clickAndHold().build().perform();

I used the Selenium 3.9.0, with previous 3.4.0 version doesn't work for me.

j.barrio
  • 1,006
  • 1
  • 13
  • 37
  • @ sagarwadhwa1 Yes,I have issue with locatiing tooltip. I guess this is tooltip element from HTML source : visibility of this tag becomes 'hidden' when mouse is out & 'visible' when hover on point on graph. – Kalyani Kachhi Jul 18 '18 at 10:46
  • I add my Java code and the detail for Selenium version, I think it is so relevant. – j.barrio Jul 18 '18 at 11:23
0

So, solution that worked for me:

WebElement elem = driver.findElement(By.xpath("//[name()='svg']//[name()='g'][5]//[name()='g'][2]//[name()='path'][1]"));
new Actions(driver).moveToElement(elem).clickAndHold().moveByOffset(1, 1).pause(1000).perform();
String text=driver.findElement(By.xpath("//[name()='svg']//[name()='g'][9]//[name()='text'][1]//[name()='tspan'][3]")).getText();