Selenium从工具提示中获取文本

时间:2018-05-13 18:47:13

标签: c# selenium-webdriver

我正在为网站编写一些自动化测试,我正在尝试验证工具提示的内容。在这种情况下,我正在使用Google Chrome进行测试。代码用C#编写。

我有一个xpath正确的元素(span),当盘旋时弹出工具提示,但我写的代码似乎永远不会弹出工具提示。如果我手动鼠标移动它。

代码如下:

    // This xpath has been verified using the google chrome extension and there is one match. This xpath matches the element that I want to hover over in order for the tooltip to appear.
    var xPathString = $"//*[text()='{dataSourceName}']/following::div[contains(@class,'somepath')]";

    var row = tblDataSources.FindElement(By.XPath(xPathString));
    TimeSpan WaitSeconds = new TimeSpan(0, 0, 0, 10);
    Thread.Sleep(WaitSeconds);

    Actions builder = new Actions(driver);
    builder.MoveToElement(row).Build().Perform();

    // This contains "TestCollector1 (+3)"
    var actualText = row.GetText();

运行测试时,弹出窗口永远不会出现,而且realText变量设置为跨度文本值,而不是悬停时应显示的工具提示值。这就是问题所在。

html如下:

<div class="col-sm-2 hidden-xs somepath"><span data-original-title="" title="">TestCollector1 (+3)</span></div>

如果我手动悬停,弹出窗口的显示方式如下: enter image description here

这是在网页中查看的范围和标签:

enter image description here

根据我所做的任何Google搜索,有没有人知道为什么代码看起来是正确的。

提前致谢

0 个答案:

没有答案