鼠标停留在图标工具提示上后,我无法获取工具提示文本。我需要获取工具提示文本,这是html代码。
<a class="tooltip" onclick="SocialAuth.showOpenIDLoginWindow('google');_gaq.push(['_trackEvent','LoginForm','google-login','google login was clicked']);" href="javascript:void(0);"><span>We dont store your password or access your contacts on your Google account.</span><img class="social" height="39" width="40" src="/images/login/google.png"/>发布于 2016-01-28 00:11:44
当工具提示是Jquery ToolTip时,从工具提示获取文本的方法与HTML不同。当getAttribute()是一个Jquery ToolTip时,它不能工作。如果您在http://demoqa.com/tooltip/上看到了工具提示示例,那么它就是一个jquery工具提示。
下面的代码可以在这里运行:
WebDriver driver=new FirefoxDriver();
driver.get("http://demoqa.com/tooltip/");
WebElement element = driver.findElement(By.xpath(".//*[@id='age']"));
Actions toolAct = new Actions(driver);
toolAct.moveToElement(element).build().perform();
WebElement toolTipElement = driver.findElement(By.cssSelector(".ui-tooltip"));
String toolTipText = toolTipElement.getText();
System.out.println(toolTipText);一个很好的参考是:
http://www.seleniumeasy.com/selenium-tutorials/how-to-verify-tooltip-text-with-selenium-webdriver-using-java
发布于 2013-10-07 15:02:11
使用下面这行代码从元素中获取工具提示文本。
String toolTipText = driver.findElement(By.id(element's id)).getAttribute("title");发布于 2015-10-05 14:49:39
为此,您必须使用操作。在此,我在Google中打印鼠标悬停消息
Actions ToolTip1 = new Actions(driver);
WebElement googleLogo = driver.findElement(By.xpath("//div[@id='hplogo']"));
Thread.sleep(2000);
ToolTip1.clickAndHold(googleLogo).perform();使用“clickAndHold”方法执行鼠标悬停操作。
使用'getAttribute‘命令获取工具提示值
String ToolTipText = googleLogo.getAttribute("title");
Assert.assertEquals(ToolTipText, "Google");
Thread.sleep(2000);
System.out.println("Tooltip value is: " + ToolTipText);https://stackoverflow.com/questions/19218404
复制相似问题