Module 17 Exercise - Combo Chart Validation | Selenium Forum
M
Posted on 31/08/2016
Hi Ashish,

I am trying to do the Combo Chart Exercise (No.10) and not able to proceed further as I am not able to extract any kind of data from the chart. So far, i was able to know the frame in which the Chart is available and switch to that frame. I have tried different options through Google Search and found this link in one of the forum posts but that couldn't help me either:
http://stackoverflow.com/questions/14199479/selenium-webdriver-validate-a-value-in-tooltip-for-a-section-bar-of-a-bar-ch

Could you please guide to solve this exercise. My Code so far is below. On execution, error saying that - "chart" is not defined. I understand we should define the chart before using but how do we define the chart when it is already defined in the code of the chart on the web page and it is in Javascript.

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;

public class BarGraph {

public static void main(String[] args) throws Exception {

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.navigate().to("https://developers.google.com/chart/interactive/docs/gallery/combochart");

/*
//Frame is a window embedded inside a page
int size = driver.findElements(By.tagName("iframe")).size();
System.out.println(size);

for(int i=0;i<size;i++){
driver.switchTo().frame(i);
int elementSize = driver.findElements(By.xpath("//*[@id='chart_div']")).size();
System.out.println(elementSize);
//prints 1 if the element is found on the frame, otherwise 0
driver.switchTo().defaultContent(); //Come out of frame. Main page
}
*/

Thread.sleep(3000);

driver.switchTo().frame(0);
System.out.println("Switched to Required Chart Frame");

//Xpath of the rectangle bars
//*[@id='chart_div']/div/div[1]/div/svg/g[3]/g[1]/g[2]/g[1]/rect[1]
//*[@id='chart_div']/div/div[1]/div/svg/g[3]/g[1]/g[2]/g[1]/rect[1]
//*[@id='chart_div']/div/div[1]/div/svg/g[3]/g[1]/g[2]/g[1]/rect[1]
//*[@id='chart_div']/div/div[1]/div/svg/g[3]/g[1]/g[2]/g[1]/rect[1]

JavascriptExecutor js = (JavascriptExecutor)driver;
int[] data = js.executeScript("return chart.series.data;");;

for(int i=0;i<data.length;i++)
System.out.println(data[i]);




}

}

M
Replied on 02/09/2016

https://developers.google.com/chart/interactive/docs/gallery/combochart

website cannot be automated.


M
Replied on 19/04/2017

Module 17 - Exercise 10 - First of all the exercise was a little vague as the points mentioned in 10.d and 10.e cannot be interpreted by me.
Thank God, I searched Google before starting to break my head.

Ashish,
If the website cannot be automated, could you please remove that from the exercise link in the Module 17. Instead give new exercise for the benefit of everyone.
Not only this, there were few which cannot be automated now owing to its limitations like Salesforce.com. If they were updated in the course materials, it would be of great help.


M
Replied on 20/04/2017

ok.