CodexBloom - Programming Q&A Platform

Selenium WebDriver struggles to extract text from a custom tooltip in a Bootstrap modal on Chrome 118

πŸ‘€ Views: 1641 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-17
selenium webdriver bootstrap chrome Python

I'm trying to figure out This might be a silly question, but This might be a silly question, but I'm having trouble using Selenium WebDriver to extract text from a custom tooltip that appears when hovering over elements in a Bootstrap modal... The tooltip is rendered using a combination of CSS and JavaScript, and the text I need is not directly available in the DOM until the tooltip is triggered by a mouse hover event. I've tried using the `moveToElement` method to hover over the trigger element, but the tooltip content isn't being captured correctly. Instead, I receive an empty string when trying to retrieve the tooltip text. Here’s a simplified version of my code: ```python from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # Setup the WebDriver (Chrome in this case) chrome_options = webdriver.ChromeOptions() driver = webdriver.Chrome(options=chrome_options) try: driver.get('http://example.com/modal') # Wait for the modal to appear wait = WebDriverWait(driver, 10) modal_element = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.modal'))) tooltip_trigger = modal_element.find_element(By.CSS_SELECTOR, '.tooltip-trigger') # Hover over the trigger element actions = ActionChains(driver) actions.move_to_element(tooltip_trigger).perform() # Attempt to retrieve the tooltip text tooltip_text = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.tooltip'))).text print('Tooltip text:', tooltip_text) except Exception as e: print('Error:', e) finally: driver.quit() ``` I’m using Chrome version 118 and the latest version of Selenium. The CSS class for the tooltip is `.tooltip`, and the tooltip only appears when hovering over the `.tooltip-trigger` element. Despite ensuring the tooltip is visible before trying to extract text, the result is still an empty string. Does anyone have suggestions for how to correctly capture the tooltip text? Are there any known issues with tooltips in Chrome that I should be aware of? I'm working in a Windows 11 environment.