2014-02-07 43 views
1

我想驗證我的網頁的NEW Button上的工具提示文本。 mousehover前新按鈕的HTML後端代碼如下:如何使用Selenium WebDriver與網頁上的java驗證工具提示文本

<button id="newBtn" class="checkForSave" title="Create a new Configuration Package" type="button">New</button> 

上新按鈕mousehover後新按鈕的HTML後端代碼如下:

<button id="newBtn" class="checkForSave" title="" type="button"> area-describdby="ui-tooltip-27"New</button> 

現在我想驗證提示在NEW按鈕上鼠標懸停後,應該出現文本「創建一個新的配置包」。

我能夠通過下面的代碼字符串中的文本鼠標懸停之前存儲:

WebElement NewButton = driver.findElement(By.id("newBtn")); 
String Tooltip = NewButton.getAttribute("title"); 
System.out.println(Tooltip); 

其打印文本「創建一個新的配置包」

但是,當我在移動鼠標新建按鈕,然後編寫代碼

Actions ActionChains = new Actions(driver); 
WebElement NewButton = driver.findElement(By.id("newBtn")); 
actions.moveToElement(NewButton).build().perform(); 
ActionChains.clickAndHold(NewButton).perform(); 
String Tooltip = NewButton.getAttribute("title"); 
System.out.println(Tooltip); 

我沒有什麼歌廳即時得到空白消息因爲經過mousehover的標題是「」在新按鈕的後臺HTML代碼。

我怎麼能這樣做?

+0

當標題變爲空白時,獲取工具提示文本非常棘手,因爲「」 –

回答

0

註釋掉行ActionChains.clickAndHold(NewButton).perform();

0
import org.openqa.selenium.interactions.HasInputDevices; 
import org.openqa.selenium.interactions.Mouse; 
import org.openqa.selenium.internal.Locatable; 

Locatable hoverItem = (Locatable) webEleObj; 
Mouse mouse = ((HasInputDevices) getDriver()).getMouse(); 
mouse.mouseMove(hoverItem.getCoordinates()); 
0

嘗試使用xpath查找元素!它可以幫助你,因爲我用「ID」&嘗試的同樣的事情,它沒有工作,而它使用Xpath而不是工作!

相關問題