2015-01-09 143 views
0

如何獲得提示使用硒的標題webdriver的This is html code for tooltip使用硒的webdriver

我的代碼檢查工具提示的標題:

starred = driver.findElement(By.xpath(".//*[@id='headerStarButton']/span")); 
builder = new Actions(driver); 
mouseover = builder.clickAndHold(starred).build(); 
mouseover.perform(); 
String title= starred.getAttribute("title"); 
System.out.println("title::" + title); 
+3

而且,有什麼例外? – Saifur

+0

不能看到給定'span'的'title'屬性。 – xyz

+0

所以可能tooltip沒有加載? – Saifur

回答

0

這是因爲提示是不存在的。要獲取工具提示進行渲染,它將在「標題」屬性中呈現文本。您正在尋找title屬性,但它不包含在xPath查找中。

你會需要它:

<span class"ico ico12 tip-below star-g-12 find-tooltip tooltipstered" title="Tooltip text here"></span> 

然後,它將工作,因爲title屬性位於您的XPath查詢。