1

I have a problem with locating an element in a span tags.

It takes part of a tooltip that appears when I put my mouse on it.

I'll show you in the following image: https://i.stack.imgur.com/b1qTg.jpg data from tooltip

When I put my mouse on that dot, the tooltip appears. I need to get that data to verify the text of the web page in Selenium Webdriver.

I've tried this code with xpath, but it doesn't return any data:

//dot of the highchart where I put my mouse to see the tooltip. Selenium Webdriver doesn't find it and it causes an error, it stops the execution here

WebElement element = driver.findElement(By.xpath(".//*[@id='highcharts-4']/svg/g[5]/g[2]/path[5]"));  //dot's xpath

// Use action class to mouse hover on the dot
Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
WebElement toolTipElement = driver.findElement(By.xpath(".//*[@id='highcharts-4']/div[1]/span"));      //xpath of the shown tooltip

// To get the tool tip text 
String toolTipText = toolTipElement.getText();

Any ideas to can get that data inside ?? Thanks so much for your help!!!!!

UserMB
  • 121
  • 2
  • 13
  • is the mouse hover working and the tooltip is displayed ? – StrikerVillain May 18 '17 at 10:26
  • @UserMB The element `highchart` is an svg element which is not within the default `xhtml` name space. Rather it's within `svg` namespace. So you need to mention the namespace as well. – undetected Selenium May 18 '17 at 10:28
  • @Sighil when I move the mouse on the dot, the tooltip appears. – UserMB May 18 '17 at 10:47
  • @Dev How can I mention the namespace? I'm pretty new here, sorry. Thanks so much!! – UserMB May 18 '17 at 10:47
  • 1
    @Sighil Look at this Question of mine (http://stackoverflow.com/questions/41829000/selenium-webdriver-java-how-to-click-on-elements-within-an-svg-using-xpath). You will get all the hints. Upvote the Question if it is Useful to you. Thanks – undetected Selenium May 18 '17 at 10:51
  • @Dev I've checked the web page that you told me, and I've tried with this command: //div[@class="highcharts-4"][contains(.,"Store Wise Performance")]/div//div[@class="highcharts-tooltip"]/*[name()="svg"]//*[name()="g"]/*[name()="path" and @fill="#2f7ed8"] but it doesn't work, it causes an error in eclipse, I don't know why... thanks!!! – UserMB May 18 '17 at 11:11
  • @Sighil `Store Wise Performance` element was exclusively for my case. In your case it would be different.I wanted you to get the idea of working with `svg` elements from that Discussion. Thanks – undetected Selenium May 18 '17 at 11:40
  • @UserMB I can have a look at your issue but as it involves svg element to be sure enough I may need the actual URL where I can access the HTML DOM. Thanks – undetected Selenium May 19 '17 at 19:18

2 Answers2

0

Solved clicking on the dot!!!

//My code WebElement element = driver.findElement(By.xpath(".//[@id='highcharts-4']/[name()='svg']/[name()='g'][5]/[name()='g'][2]/*[name()='path'][1]"));

    // Use action class to mouse hover on Text box field
    Actions action = new Actions(driver);
    action.click(element).build().perform();
UserMB
  • 121
  • 2
  • 13
0

use below:

\\first click the dot using your code:
Actions action = new Actions(driver);
action.click(element).build().perform();

\\then use following code to get your data :

System.out.println("First line of Tooltip" + driver.findElement(By.cssSelector("div > div.highcharts-tooltip > span span:nth-child(1) > b")));

System.out.println("Second line of Tooltip" + driver.findElement(By.cssSelector("div > div.highcharts-tooltip > span span:nth-child(2) > b")));
Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46