Question

` enter image description here How to write code to print a tooltip message in python?

I am using the following code to move my pointer to the element on the web page:

element = driver.find_element_by_css_selector("locator")
webdriver.ActionChains(driver).move_to_element(element).perform()
time.sleep(3)

Also, our developer is using the same class for all the tool tip messages on that page so I don't know how to print that particular tooltip message.

HTML code:

<div class="d3-tip n" style="position: absolute; opacity: 0; pointer-events: none; top: 1108px; left: 116px;"><div><strong>Table Name:</strong> <span style="color:#1F77B4">lineitem</span></div><div><strong>Number of Queries:</strong> <span style="color:#1F77B4">13</span></div></div> 

I want to print the "lineitem" and "13" from the above div tag

But as I mentioned this is another div tag with the same class that has a different tool tip message:

<div class="d3-tip n" style="position: absolute; opacity: 0; pointer-events: none; top: 469px; left: -180.23684692382813px;">select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier s join revenue r on s.s_suppkey = r.supplier_no join (select max(total_revenue) as m from revenue) mr on r.total_revenue = mr.m order by s_suppkey </div>
Was it helpful?

Solution

According to the info you've provided, you can get the desired div by the text inside.

For example, you can check for Table Name: text using the xpath:

element = driver.find_element_by_xpath("//div[./div/strong, 'Table Name:']")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top