gpt4 book ai didi

java - 如何在selenium java中处理工具提示

转载 作者:行者123 更新时间:2023-12-02 01:31:49 25 4
gpt4 key购买 nike

Tooltip image无法使用 selenium java 中的 getAttribute 和 getText 处理工具提示。下面是代码

HTML:

<span class="exclude-syndicated-hint hint--top" data-hint="Programs like 
&quot;The Today Show&quot; 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/

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