Home > OS >  Highcharts: Trigger showing tooltip programatically with selenium
Highcharts: Trigger showing tooltip programatically with selenium

Time:11-30

I have the situation where I need to create some automatic actions with selenium on a third party website (which I assume means that I can't use the highcharts api).

When the third party website is loaded, there is no tooltip element in the html body. It seems that it is dynamically added when the cursor is hovering over the chart.

I would like to for the tooltip to be shown via java selenium. If there is a javascript way to do this please let me know and I will try to transfer it to the selenium code myself

So far I have tried via the browser console with javascript to trigger a 'mouseover' event or to add a 'hover' class to different elements inside the highcharts container but I had no luck, the tooltip is not added to the html body and therefore I cannot select it.

I believe the above issue can be reproduced with the element with highcharts-tooltip class is not added to the html body until the user hovers on the chart.

CodePudding user response:

You should be able to get global Highcharts variable and call onMouseOver method on a specific point.

Highcharts.charts[0].series[0].points[0].onMouseOver();

You can also dispatch mousemove event directly on a svg element.

document.getElementsByClassName('highcharts-point')[0].dispatchEvent(new Event('mousemove', { 'bubbles': true }));

API Reference: https://api.highcharts.com/class-reference/Highcharts.Point#onMouseOver

  • Related