Not able to get tooltip text using Selenium WebDriver

☆樱花仙子☆ 提交于 2019-12-08 04:55:18

问题


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.


回答1:


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"));



回答2:


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"));

http://www.javascriptkit.com/howto/toolmsg.shtml




回答3:


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();



回答4:


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.



来源:https://stackoverflow.com/questions/8739989/not-able-to-get-tooltip-text-using-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!