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

标签 java selenium

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/

相关文章:

java - Selenium |命名空间错误: Failed to execute 'evaluate' on 'Document' | Contains unresolvable namespaces

java - Selenium 处理 AuthenticateRequired - java

java - 在 Java 中从 HTTP 响应解析 JSON 数组

java - 如何混淆tomcat日志文件中的请求属性

java - GWT Maven 集成

java - 将结果更新到 Android 的 AlertDialog 的 TextView

python - 无法在 Mac OS X 上的 selenium webdriver 中打开新选项卡

javascript - Selenium webdriver 在 node.js 中迭代和导航多个链接

java - 我们如何从 java 运行 python 脚本(使用 nltk 和 scrapy)

java - 每秒捕获屏幕图像并将其显示在应用程序上是否有效?