在javascript动态加载工具提示的情况下,如何使用selenium提取工具提示内容?
我正在测试一个web应用程序,在这个应用程序中,我需要验证在将鼠标移到图形的一部分上时显示的工具提示的内容 以下是本技巧的html代码部分:在javascript动态加载工具提示的情况下,如何使用selenium提取工具提示内容?,javascript,selenium,python-2.7,tooltip,Javascript,Selenium,Python 2.7,Tooltip,我正在测试一个web应用程序,在这个应用程序中,我需要验证在将鼠标移到图形的一部分上时显示的工具提示的内容 以下是本技巧的html代码部分: <div id="area-serverSlot-6a" class="annotation" style="width: 21px; height: 38px; left: 186px; top: 117px; position: absolute; z-index: 20; cursor: pointer;" name="annotation"
<div id="area-serverSlot-6a" class="annotation" style="width: 21px; height: 38px; left: 186px; top: 117px; position: absolute; z-index: 20; cursor: pointer;" name="annotation" present="1" tooltip="" href="javascript:select_module('server', '6a');" onareaover="javascript:DisplayTip('serverSlot-6a', TITLE,'Server Slot 6a')" onareaout="javascript:UnTip()"></div>
尼克
我以Linkedin为例
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.linkedin.com/");
WebElement onElement = driver.findElement(By.xpath("html/body/div[1]/div[1]/div/h2/a"));
System.out.println("Tooltip : " + onElement.getAttribute("title"));
嘿,Adi,上面的代码片段中没有显示title属性。如果有title,我可以很容易地使用getattribute。您的代码中有属性title(title,'Server Slot 6a')Adi,该标题是java脚本函数的参数,而不是html代码的属性。我怎么读这个标题?尼克,当你手动将鼠标悬停在元素上时,你是否看到显示的工具提示?即使原始html文档不包含该元素的
title
属性,但在JavaScript添加它之后,它应该出现在“计算源代码”中。因此,如果您看到显示的工具提示,Selenium的getAttribute(“title”)
在这一点之后仍应返回您正在查找的信息。您能否显示DisplayTip()的JS
?嘿@PatMeeker,我已经包含了上面DisplayTip的代码。
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.linkedin.com/");
WebElement onElement = driver.findElement(By.xpath("html/body/div[1]/div[1]/div/h2/a"));
System.out.println("Tooltip : " + onElement.getAttribute("title"));