How to Validate the bars in chart?

package exercises;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class GoogleBarChart {

WebDriver driver;
WebDriverWait wait;
@Test
public void Test1() throws InterruptedException
{
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.navigate().to(“https://developers.google.com/chart/interactive/docs/gallery/combochart”);

List<WebElement> frames = driver.findElements(By.tagName(“iframe”));
System.out.println(“Total Frames :”+frames.size());

driver.switchTo().frame(0);

String Heading = driver.findElement(By.xpath(“//*[local-name()=’svg’]/*[local-name()=’g’]/*[local-name()=’text’]”)).getText();

System.out.println(“Pi_CHART HEADING IS :”+Heading);

// List of test xpath : //*[local-name()=’svg’]/*[local-name()=’g’]/*[local-name()=’g’]/*[local-name()=’g’]/*[local-name()=’text’]

List<WebElement> Cities_Lst = driver.findElements(By.xpath(“//*[local-name()=’svg’]/*[local-name()=’g’]”
+ “/*[local-name()=’g’]/*[local-name()=’g’]/*[local-name()=’text’][@text-anchor=’start’]”));

System.out.println(“————————————————————–“);
System.out.println(“THIS PI_CHART CONTAINS THE FOLLOWING CITY NAMES :”);

for(int j=0; j<Cities_Lst.size();j++)
{
System.out.println(Cities_Lst.get(j).getText());
}

System.out.println(“————————————————————–“);

// Get the List of month in the chart
System.out.println(“***********MONTH OF CHART************”);
//*[local-name()=’svg’]/*[local-name()=’g’][3]/*[local-name()=’g’][3]/*[local-name()=’g’]/*[local-name()=’text’][@text-anchor=’middle’]

List <WebElement> Month_List = driver.findElements(By.xpath(“//*[local-name()=’svg’]/*[local-name()=’g’][3]/*[local-name()”
+ “=’g’][3]/*[local-name()=’g’]/*[local-name()=’text’][@text-anchor=’middle’]”));

for(int j=0; j<Month_List.size();j++)
{
System.out.println(Month_List.get(j).getText());
}
System.out.println(“————————————————————–“);

// Get the List of cups in the chart:
System.out.println(“***********CUPS OF CHART************”);
List<WebElement> Cups_List= driver.findElements(By.xpath(“//*[local-name()=’svg’]/*[local-name()=’g’][3]/*[local-name()=’g’]”
+ “[3]/*[local-name()=’g’]/*[local-name()=’text’][@text-anchor=’end’]”));

for(int j=0; j<Cups_List.size();j++)
{
System.out.println(Cups_List.get(j).getText());
}

System.out.println(“————————————————————–“);
driver.switchTo().defaultContent();

// Get the Each and every month individual sales cups in city based:
Actions act = new Actions(driver);

List<WebElement> Sales_PerMonth=driver.findElements(By.xpath(“//div[@aria-label=’A tabular ”
+ “representation of the data in the chart.’]/table/tbody/tr/td”));

for(int i=0;i<Sales_PerMonth.size();i++)
{
act.moveToElement(Sales_PerMonth.get(i)).build().perform();
System.out.println(Sales_PerMonth.get(i).getText());
}
}

Above this code get the month and cups and cities values only..

(i) How i will get the Each and every cities cups manufacturing values (bars values).

This xpath is not working…
//div[@aria-label=’A tabular representation of the data in the chart.’]/table/tbody/tr/td

because this div tag is hidden..

In this case how i will get the hidden values…

Please help me..

jakay Default Asked on July 16, 2016 in Selenium WebDriver.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.