gpt4 book ai didi

java - 如何捕获工具提示及其文本

转载 作者:太空宇宙 更新时间:2023-11-04 12:16:13 25 4
gpt4 key购买 nike

我正在 try catch Selenium 中工具提示的文本。使用下面的代码。

    WebElement element = driver.findElement(By.id("age"));

Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
WebElement toolTipElement = driver.findElement(XXXXXXXXX);
toolTipElement.getattribute("title");

但问题是我无法捕获工具提示元素。当我悬停时它会显示,但当我移动光标时它会立即消失。如何捕获这样的工具提示。请帮忙

最佳答案

有两种方法可以实现,

如果您的 HTML 看起来像,带有属性“标题”

<div id="header" >
<a title="I am an anchor Tag">Mouse over</a>
</div>

WebElement element = driver.findElement(By.cssSelector("#header")); //Note: this is expected element

String toolTipText = element.getAttribute("title");

或者在预期元素上没有属性“title”

<div id="header" class="ui-tooltip ui-widget ui-corner-all ui-widget-content">
<a id="aId"> Mouse over </a>
</div>

WebElement element = driver.findElement(By.cssSelector("#header"))

Actions action = new Actions(driver); action.moveToElement(element).build().perform();

WebElement toolTipElement = driver.findElement(By.cssSelector(".ui-tooltip")); //Note: this is parent element

String toolTipText = toolTipElement.getText();

//Your assert here

关于java - 如何捕获工具提示及其文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39386061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com