Tooltip image无法使用 selenium java 中的 getAttribute 和 getText 处理工具提示。 下面是代码
HTML:
<span class="exclude-syndicated-hint hint--top" data-hint="Programs like
"The Today Show" are often syndicated across major networks and
play on a variety of channels. Checking this box will only give you a
single copy of the program.">
<i class="syndicated-hint-icon fa fa-info-circle"></i>
</span>
JAVA:
@FindBy(xpath = "//i[@class='syndicated-hint-icon fa fa-info-circle']")
public WebElement tooltip;
public String settooltip()
{
Actions a = new Actions(driver);
a.moveToElement(tooltip).perform();
String actualTooltip = tooltip.getAttribute("data-hint");
}
最佳答案
// Create action class object
Actions builder=new Actions(driver);
// find the tooltip xpath
WebElement _tooltip=driver.findElement(By.xpath("//span[@class='exclude-syndicated-hint hint--top']));
// Mouse hover to that text message
builder.moveToElement(_tooltip).perform();
// Extract text from tooltip
String tooltip_msg=_tooltip.getAttribute("data-hint");
// Print the tooltip message just for our refrences
System.out.println("Tooltip message is "+tooltip_msg);
关于java - 如何在selenium java中处理工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55914248/