I want to simulate mouse hover on this site on this element using only javascript with selenium.
#main > div > div > div.Blockreact__Block-sc-1xf18x6-0.elqhCm > div > div.fresnel-container.fresnel-greaterThanOrEqual-xl.fill-remaining-height > div > div.Blockreact__Block-sc-1xf18x6-0.Flexreact__Flex-sc-1twd32i-0.FlexColumnreact__FlexColumn-sc-1wwz3hp-0.bEcedX.jYqxGr.ksFzlZ > div.Blockreact__Block-sc-1xf18x6-0.duVYOV > div > div.PriceHistory--graph > div > div > div.recharts-wrapper > svg > g.recharts-layer.recharts-bar > g > g:nth-child(80)
I have looked at various posts like this and this. However, nothing seems to be working on this site.
I tried using this code, but it isn't working on the site.
const mouseoverEvent = new Event('mouseover');
$('#main > div > div > div.Blockreact__Block-sc-1xf18x6-0.elqhCm > div > div.fresnel-container.fresnel-greaterThanOrEqual-xl.fill-remaining-height > div > div.Blockreact__Block-sc-1xf18x6-0.Flexreact__Flex-sc-1twd32i-0.FlexColumnreact__FlexColumn-sc-1wwz3hp-0.bEcedX.jYqxGr.ksFzlZ > div.Blockreact__Block-sc-1xf18x6-0.duVYOV > div > div.PriceHistory--graph > div > div > div.recharts-wrapper > svg > g.recharts-layer.recharts-bar > g > g:nth-child(80)').dispatchEvent(mouseoverEvent)
Due to some problems I can only use javascript and not Actionchains like most posts describe. Any solution without ActionChains should work fine.
I just want to get the data that is displayed after the mouse hover event is triggered. It can be done manually and with ActionChains but I want it to be done with JS. Link to the screenshot As It can be seen from the image a tooltip appears after the mouse hovers on the graph. I can simulate the behaviour with ActionChains by using this code.
#Scroll a little bit to load all the elements
driver.execute_script("window.scrollTo(0, 500);")
XPath = "//*[@class='recharts-layer recharts-bar-rectangle']"
bar = driver.find_elements('xpath',XPath)[-1] #Since I want to get the latest data
ActionChains(driver).move_to_element(bar).perform()
#Now get the data
XPATH_TOOLTIP = "//div[@class='PriceHistory--tooltip']"
data = driver.find_element('xpath',XPATH_TOOLTIP).text
print(data)
I want the tooltip to appear using JS.
Is it possible to simulate the mouse hover on the element? Also, why does the code work on some sites but not on others, for example, works on this?