44424

Not able to get tooltip text using Selenium WebDriver

Question:

I have 5 tooltips in page. Using WebDriver, I am trying to verify these tooltip text.

I am using following code sequentially to get the tooltip text of all 5 elements:

Actions builder = new Actions(WebDriver); builder.ClickAndHold(Element1).Perform(); Console.WriteLine(Element1ToolTip.text); builder.ClickAndHold(Element2).Perform(); Console.WriteLine(Element2ToolTip.text); builder.ClickAndHold(Element3).Perform(); Console.WriteLine(Element3ToolTip.text);

The issue is I get only the tooltip text of first element printed in console. Is it because I need to refresh or reset the builder?

It's really weird when I delete the code for 1st element , then I can get tooltip text of 2nd element. So, basically it is getting tooltip text only once in single execution.

Answer1:

Verify tool tip by comparing "title" attribute of the web element and your expected tool tip text.

Console.WriteLine(Element1.GetAttribute("title")); Console.WriteLine(Element2.GetAttribute("title"));

Answer2:

Tool tip text for input elements would be the title attributes and for images, alt attribute would be the tool tip.This is the standard for HTML 4, so I am not sure if you need to do hover and all.

Console.WriteLine(InputElement1.GetAttribute("title")); Console.WriteLine(ImageElement1.GetAttribute("alt"));

<a href="http://www.javascriptkit.com/howto/toolmsg.shtml" rel="nofollow">http://www.javascriptkit.com/howto/toolmsg.shtml</a>

Answer3:

I think, it needs to release from element as:

builder.release(Element1).perform();

So, your code could be as below:

Actions builder = new Actions(WebDriver); builder.ClickAndHold(Element1).Perform(); Console.WriteLine(Element1ToolTip.text); builder.release(Element1).perform(); builder.ClickAndHold(Element2).Perform(); Console.WriteLine(Element2ToolTip.text); builder.release(Element2).perform(); builder.ClickAndHold(Element3).Perform(); Console.WriteLine(Element3ToolTip.text); builder.release(Element3).perform();

Answer4:

I am facing the same issue , i checked the view source page on running the test and it appears that the title attribute is displayed as data-original-title.Due to which it is unable to display the text.On replacing the title with data-original-title . I am able to obtain text.

Recommend

  • Are there any good examples of how to take a screenshot in selenium webdriver C#, then crop and save
  • Comparing elements of data.frames in R
  • How to cache images only in disk using Kingfisher?
  • ActiveAdmin “f.inputs, except: [:field]” doesn't work
  • How to check Eclipse plugin performance
  • Delete multiple lines - from “patternA” match, through second occurrence of “patternB”
  • Why do native C++ projects have a TargetFrameworkVersion?
  • How can i automate 'Settings' app in real iOS devices?
  • How to insert an Image in WORD after a bookmark using OpenXML
  • Vim ctags behaves strangely
  • Eclipse: missing requirement E4 RCP patch when installing properties editor
  • Android libgdx prefs getting lost
  • Find symbol dependencies in source code [closed]
  • Sending rails errors to rspec output
  • How to run bash commands like “npm install” on complie
  • How to extract a number from a string [duplicate]
  • UML diagram generator in Visual Studio 2010
  • React Router and Arbitrary Query Params: Page Refreshes Unintentionally on Load?
  • WP7 difficulties binding data to listbox itemssource - won't refresh
  • Javascript focus remove text highlight
  • Why doesnt this Java loop in a thread work?
  • using html data-attributes as css-variable (i.e. text-shadow)
  • Click on button in another program - FindWindow, C#
  • VSCode change debug shell to bash on windows
  • Does Apple allow the usage of sysctl.h within iOS applications?
  • Multiple producers single consumer locking schema
  • Tell Git to stop prompting me for conflicts when none really exist?
  • Low TTL with Leveled Compaction, should I reduce gc_grace_seconds to improve read performance withou
  • Silverlight DependencyProperty.SetCurrentValue Equivalent
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • Moving mysql files across servers
  • Knitr HTML Loop - Some HTML output, some R output
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Upload files with Ajax and Jquery
  • Weird JavaScript statement, what does it mean?
  • How to pass list parameters for each object using Spring MVC?
  • Data Validation Drop Down Box Arrow Disappearing
  • Proper way to use connect-multiparty with express.js?
  • Django query for large number of relationships