无法使用 Selenium WebDriver 获取工具提示文本 [英] Not able to get tooltip text using Selenium WebDriver

查看:36
本文介绍了无法使用 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"));

这篇关于无法使用 Selenium WebDriver 获取工具提示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆