无法使用 Selenium WebDriver 获取工具提示文本

无法使用 Selenium WebDriver 获取工具提示文本

问题描述:

我在页面中有 5 个工具提示.使用 WebDriver,我正在尝试验证这些工具提示文本.

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

我按顺序使用以下代码来获取所有 5 个元素的工具提示文本:

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.

通过比较 Web 元素的title"属性和您预期的工具提示文本来验证工具提示.

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