Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript动态加载工具提示的情况下,如何使用selenium提取工具提示内容?_Javascript_Selenium_Python 2.7_Tooltip - Fatal编程技术网

在javascript动态加载工具提示的情况下,如何使用selenium提取工具提示内容?

在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"

我正在测试一个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" 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"));