2016-01-04 16 views
0
public void testSuccess() throws InterruptedException { 
    System.out.println("test arribute popup"); 
    Thread.sleep(3000); 

    WebElement searchBtn = driver.findElement(By.xpath(".//*[@id='investedList']/span/span[2]/span")); 


    Actions action = new Actions(driver); 
    action.moveToElement(searchBtn).perform(); 
    Thread.sleep(3000); 

} 

當鼠標移動到按鈕有彈出文本顯示爲「投資清單」 如何測試這個使用硒如何測試文本,其彈出時,鼠標移動到按鈕,在硒

+0

你試過方法'.Gettext();'? –

+0

yes.it不起作用 –

+0

首先您捕獲該文本的元素定位器。然後使用getText()函數來讀取文本。 –

回答

0

試試這個代碼:

List<WebElement> overlaysTooltips = driver.findElements(By.xpath(".//*[@id='investedList']/span/span[2]/span")); 

for(int i = 0; i < overlaysTooltips.size(); i++){ 

    Actions builder = new Actions(driver); 
    builder.moveToElement(overlaysTooltips.get(i)).perform();  

    //get button text after hover 
    if((overlaysTooltips.get(i).getAttribute("value").equals("//ur button hover string")){ 
       //ur condition 
       Thread.sleep(3000); 
      } 
    } 

你可以使用其他按鈕屬性什麼是你的HTML代碼,因爲我不知道你的HTML代碼中有什麼樣的屬性。 是這樣的:

overlaysTooltips.get(i).getAttribute("id") 
or 
overlaysTooltips.get(i).getAttribute("class") 
or 
overlaysTooltips.get(i).getAttribute("name") 
相關問題