In previous post we have seen what are Actions, in this section using Actions will automate SVG HighCharts.
Below script will open chrome browser and navigate to http://www.highcharts.com/demo/bar-basic
and then mouse move to particular data point element and display the tooltip information.
Script :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.interactions.Actions; | |
public class HighchartsToolTip { | |
public static void main(String[] args) throws InterruptedException { | |
// TODO Auto-generated method stub | |
//WebDriver webdriver=new FirefoxDriver(); | |
// System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe"); | |
WebDriver myTestDriver=new FirefoxDriver(); | |
myTestDriver.get("http://www.highcharts.com/demo/bar-basic"); | |
Thread.sleep(8000); | |
// css selector for data point. | |
WebElement element = myTestDriver.findElement(By.cssSelector("rect.highcharts-color-2:nth-child(2)")); | |
// using actions class to move to the above element | |
Actions builder = new Actions(myTestDriver); | |
builder.moveToElement(element).build().perform(); | |
Thread.sleep(3000); | |
//*[@id="highcharts-0"]/svg/g[11]/text[1] | |
String tooltip = myTestDriver.findElement(By.cssSelector("g.highcharts-legend-item:nth-child(3) > text:nth-child(1) > tspan:nth-child(1)")).getText(); | |
System.out.println(tooltip); | |
} | |
} |
output on the console
Africa