Python: reading data from Highcharts after setExtreme

I am trying to get data from a Highcharts chart using Selenium. The problem with this is that the setExtremes function setExtremes not work with .options.data . How to read data after using setExtremes using pure Python based methods?

My code is:

 capabilities = webdriver.DesiredCapabilities().FIREFOX capabilities["marionette"] = True driver = webdriver.Firefox(capabilities=capabilities, executable_path=gecko_binary_path) driver.get(website) time.sleep(5) temp = driver.execute_script('return window.Highcharts.charts[0].series[0]' '.xAxis[0].setExtremes(Date.UTC(2017, 0, 7), Date.UTC(2017, 0, 8))' '.options.data' ) data = [item for item in temp] print(data) 
+8
javascript python html selenium highcharts
source share
1 answer

The problem is that the setExtremes(min, max) method returns undefined , so you cannot bind parameters. The solution is to wrap this method and pass the context, for example:

 (function(H) { H.wrap(H.Axis.prototype, 'setExtremes', function (proceed) { proceed.apply(this, Array.prototype.slice.call(arguments, 1); return this; // <-- context for chaining }); })(Highcharts); 

Now we can use:

 return window.Highcharts.charts[0].xAxis[0].setExtremes(min, max).series[0].options.data; 

Note: the fragment can be placed in a separate file and used like any other Highcharts plugin (just download it after the Highcharts library).

Attention!

An Axis object only has links to series attached to this axis. If you want to access any series on the chart, use:

 return window.Highcharts.charts[0].xAxis[0].setExtremes(min, max).chart.series[0].options.data; 
-2
source share

All Articles