How do I automate pie and bar charts using selenium?
Finding the xpath of elements inside the svg tag is bit different from finding the xpath of other elements.
Let's assume your url is:
https://developers.google.com/chart/interactive/docs/gallery/piechart
If you need to find the text of an element in a pie chart, you can use the below code:
driver.findElement (By.xpath ("// [@ id = 'piechart'] / div / div [1] / div / [name () = 'svg'] / [name () = 'g'] [4 ] / [name () = 'text'] ")). getText ();
source to share
I need to automate a lot of pages that make heavy use of different Kendo controls. I work at Telerik and we use Test Studio for our automation. However, you can apply our approach. I usually read the javascript API documentation for the control I want to automate. There are many methods that can be performed for each one.
Example: http://docs.telerik.com/kendo-ui/api/javascript/kendo You just need to find the appropriate method for your case and javascript it through the web driver:
WebDriver driver = new AnyDriverYouWant();
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor)driver).executeScript("yourScript();");
}
You can create extension methods around controls for these specific methods.
If you have any questions, do not hesitate to contact me!
source to share
ya i got the solution .... this is the code to drill down in the diagram
WebElement svg = gd.findElement(By.cssSelector("svg"));
List<WebElement> outertext = svg.findElements(By.cssSelector("text"));
for(WebElement texts : outertext)
{
String textcollection = texts.getText();
if(textcollection.equals("xxxxxx"))
{
texts.click();
}
}
source to share