1

` 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>
12
  • Please show the example html code containing several tooltips, note which one you need. Thanks. Commented May 1, 2014 at 17:38
  • 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 Commented May 1, 2014 at 17:46
  • Please edit the question and include the html into it. Commented May 1, 2014 at 17:46
  • 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 Commented May 1, 2014 at 17:47
  • Ok, thanks. You can use the fact that those tooltips are in different parts of a web page and find the right one based on it's parent and page location, using xpath expression. It's impossible to help you, since I don't know where these div tags are on a web page. Could you share a link? Commented May 1, 2014 at 17:50

1 Answer 1

1

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:']")
Sign up to request clarification or add additional context in comments.

10 Comments

Hi, The question is not related to the above issue but just wanted to ask you if you could help me on "how we can create a Test Suite" in python. I have a couple of test cases and I want to add them to a Test Suite so I can execute both of them at once from the command prompt without calling them individually. Can you help me with this please?
@user3587233 instead of making a test suite, consider using nose or py.test test runner. It would discover your test cases automagically.
Sorry, it might be a very silly question but what if I want to include only some tests in a single run and not all the test cases from that directory? Will nose help me with that too?
Hi, Can I ask your help with an xpath expression for a different issue in this question?
@user3587233 probably creating a separate question would be a good idea. Throw a link to it here in comments. Thanks.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.