'How do I scrape the text that appears when I hover over the element?
So on the e-commerce webpage (https://www.jooraccess.com/r/products?token=feba69103f6c9789270a1412954cf250) the color name of the product is displayed when I hover over it, I was able to determine what the new line in HTML code that appears when I hover over, but I don't know how to grab the text ('NAVY').
<div class="ui top left popup transition visible Tooltip_Tooltip__M0LJL Tooltip_black__heZoQ" style="position: absolute; inset: auto auto -7494px 378px;">NAVY</div>
driver.get("https://www.jooraccess.com/r/products?token=feba69103f6c9789270a1412954cf250")
elements = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@class='Swatch_swatch__2X1CY']")))
for el in elements:
ActionChains(driver).move_to_element(el).perform()
mouseover = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='ui top left popup transition visible Tooltip_Tooltip__M0LJL Tooltip_black__heZoQ'")))
print(mouseover)
Solution 1:[1]
I have checked your code.Your xpath expression seems wrong for tool tip element.
I have changed that and also to get the text value you need to print(element.text)
driver.get("https://www.jooraccess.com/r/products?token=feba69103f6c9789270a1412954cf250")
elements = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@class='Swatch_swatch__2X1CY']")))
for el in elements:
ActionChains(driver).move_to_element(el).perform()
mouseover = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='ui top left popup transition visible Tooltip_Tooltip__M0LJL Tooltip_black__heZoQ']")))
print(mouseover.text)
Solution 2:[2]
for some reason I couldn't get your site to work with the platform I am using but I managed to create an example. I would recommend using the Actions library and use it to move to the element in question.
ActionChains(self.driver).move_to_element(self.driver.find_element(By.XPATH, "//a[@class='dropdown-toggle']")).perform()
This is for the site I am using but if you change the xpath for your own element it should work. Once the driver has done this you can find the element you want that is revealed by hovering. You should be able to just put this in a for loop and you are good to go.
I made a runnable example here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KunduK |
| Solution 2 | Marko Delic |

