【问题标题】:capture tooltip of a button using selenium使用 selenium 捕获按钮的工具提示
【发布时间】:2013-02-12 12:00:07
【问题描述】:

我是 Selenium 初学者。不知道如何从以下 html 代码中捕获工具提示。 这是html的结构:

<a id="aui_3_4_0_1_2236" title="Graceful shut down of the platform and power-off the hardware.">
    <span id="aui_3_4_0_1_2235" class="aui-button">
        <span id="aui_3_4_0_1_2234" class="aui-button-`enter code here`content">
            <input id="_PlatformSummaryPortlet_WAR_CPFSPGPortlet10SNAPSHOT_INSTANCE_AEDwGJz6R6iD_soft" class="aui-button-input" type="button" value="Soft Shutdown" onclick="javascript:soft()" style="display: inline;"/>
        </span>
    </span>
</a>

并且标题具有工具提示值。 我尝试了以下方法来获取工具提示:

WebElement Softshtdwn = driver.findElement(By.xpath(Object.SoftShutdownButton)); 
String tooltip = Softshtdwn.getAttribute("title");
String tooltip1 = Softshtdwn.getText(); 
String tooltip2 = Softshtdwn.getCssValue("title");

但由于某种原因,我得到了 null 值作为回报。 任何帮助表示赞赏。 注意:不能使用 by.ID,因为 ID 是动态的。

【问题讨论】:

  • 工具提示周围的 HTML 是什么样的?
  • 我希望我可以添加截图。 :)。这里是 HTML
    ,正在寻找优雅的关机。谢谢
  • 已经修改了您的帖子,您确实已经包含了您的原始 HTML,但它被隐藏了,因为您的格式不正确。
  • 您能否确认您正在寻找的确切工具提示?您的代码似乎在寻找“软关机”按钮 ((By.xpath(Object.SoftShutdownButton)),对吗?
  • 是的,我已经为价值软关机提供了 xpath。但我正在寻找该按钮的工具提示,即 title="正常关闭平台并关闭硬件。"

标签: java html selenium


【解决方案1】:

使用以下逻辑,您可以获得工具提示

但是,请确保您使用正确且唯一的定位器来获得完全需要的值。

String toolTip=driver.findElement(By.xpath("")).getAttribute("title");

如果您无法构建正确的 xpath,请在此处发布您的 html 代码。我会帮你的。

【讨论】:

  • 我已经完成了类似的步骤。但它为我返回空值。我在问题块中添加了确切的 HTML 代码。任何帮助将不胜感激。
  • 试试这个定位器:By.id("aui_3_4_0_1_2236")
  • 对不起,我粘贴在我的问题中的上一个代码中有一个错误。请找到确切的代码: 没有 ID
  • 试试这个定位器:By.xpath("//table//td/a[3]")
猜你喜欢
  • 2019-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多