Different versions of this question have already been asked:
How can I locate a onmouseover element using Selenium in Python?
How to emulate mouseover or run JS function on page with PhantomJS in NodeJS
Basically what I want to do is to get the text from a table cell that displays when the mouse is over, as seen in the image below. I code in Python and use Beautiful Soup
I can successfully get the onmouseover attribute using Beautiful Soup:
<td class="right odds down"><div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','357osx2s5a4x0x7ot9r',2,event,0,1)">+340</div></td>
<div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','357osx2s5a4x0x7ot9r',2,event,0,1)">+340</div>
My question is. How can I get the text (the initial odd) using the attribute:
onmouseover="page.hist(this,'P-0.00-0-0','357osx2s5a4x0x7ot9r',2,event,0,1)
Any help is greatly appreciated.
Ok the answer is actually to get the information with Selenium webdriver. For example if we want to get initial odds from bwin, which the 8th row in our odds-data-table: its x-path is:
"//*[@id =" + '"odds-data-table"' + "]/div[1]/table/tbody/tr[8]/td[2]")
and we can retrieve the initial odd data by first hovering over it and getting the info as such:
initial_odd_data = driver.find_element_by_xpath("//*[@id =" + '"odds-data-table"' + "]/div[1]/table/tbody/tr[8]/td[2]")
hov = ActionChains(driver).move_to_element(initial_odd_data)
hov.perform()
data_in_the_bubble = driver.find_element_by_xpath("//*[@id='tooltiptext']")
hover_data = data_in_the_bubble.get_attribute("innerHTML")