Skip to content
Advertisement

How can I get the tooltip text from a website using selenium and python where the text comes from a javascript

I am trying to get the tooltip text that shows when I hover over how long ago the game was played https://www.leagueofgraphs.com/summoner/eune/AnFrey99 enter image description here]1

In the html code it doesn’t shows the text and I figure it comes from a javascript and each rows has a script inside the tr tag, but so far I was not able to get the value of the var newTooltipData .

    var newTooltipData = {"match-2733966814": (new Date(1612964002882).toLocaleDateString() + " " + new Date(1612964002882).toLocaleTimeString()) + " - 31min 48s"};
    if (window.tooltipData) {
        window.tooltipData = Object.assign(window.tooltipData, newTooltipData);
    } else {
        window.tooltipData = newTooltipData;
    }

I want to get the exact date for each row along with other information that I already done. Here is my code and my tries.
JavaScript

Advertisement

Answer

If you hover the div, JavaScript will append a new div to the website with the ID 'tooltip' (full source of the function here):

JavaScript

Therefore Selenium can find this new div id = “tooltip” after you hover over the div, which calls this function.

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement