我正在尝试获取图像的工具提示文本,并希望存储在变量中。下面是HTML Code.script能够执行鼠标悬停事件并显示工具提示文本值。但无法获取工具提示文本值。请帮助我。
<img onmouseover="var relNo=getReleaseNo(); this.T_ABOVE = false; this.T_OFFSETY=-10; this.T_OFFSETX=10; this.T_WIDTH=200; this.T_DELAY=1000; return escape('<table><tr><td align=center>Welcome to the Daimler EngineeringPortal<br><b>' + relNo + '</b></td></tr></table>');" src="./pics/logo/logo_mini.jpg">
PFA下面提到的是selenium脚本。在脚本中,所有事情都在起作用,无法得到文本 Selenium脚本
package All_Module_Engp;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
public class Engp_Module {
public static void main(String args[])
{
File pathToBinary = new File("C:/Users/rrimjhi/AppData/Local/Mozilla Firefox/firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(ffBinary,firefoxProfile);
driver.get("https://tindito.COM");
driver.findElement(By.id("usr")).sendKeys("xyz123");
driver.findElement(By.id("password")).sendKeys("xyz123");
driver.findElement(By.name("login")).click();
driver.manage().window().maximize();
// String s = driver.getTitle();
// System.out.println(s);
Actions tooltip = new Actions(driver);
driver.switchTo().frame("header");
WebElement img1=driver.findElement(By.xpath("//img[@src='./pics/logo/logo_mini.jpg']"));
tooltip.clickAndHold(img1).perform();
String ToolTipText = img1.getText();
System.out.println(ToolTipText);
}
}
答案 0 :(得分:0)
试试这个:
WebElement elementWithTooltip = driver.findElement(By.xpath("//img[@src='./pics/logo/logo_mini.jpg']"));
Actions builder = new Actions(driver);
builder.moveToElement(elementWithTooltip).build().perform();
//try to find this tool tip element and verify the text
WebElement tooltip = driver.findElement(By.id("tooltip"));
assertEquals("tooltip content", tooltip.getText());