2016-02-05 30 views
0

有一個按鈕。當你點擊這個按鈕時,會出現一個有兩個選項的下拉菜單。如何在java中使用selenium來驗證這個場景。如何驗證在java中使用硒的下拉菜單按鈕

<div class="hpDropDownButton"> 
<button class="button ng-binding">Holidays Operation</button> 
<ul> 
    <li> 
     <a class="ng-binding" ng-click="uploadHolidays()">Upload Holidays</a> 
    </li> 
    <li> 
     <a class="ng-binding" ng-click="deleteHolidays()">Delete Holidays</a> 
    </li> 
</ul> 

+0

開始webdriver的,找到按鈕,點擊它,找到這兩個菜單,然後斷言屬性isDisplayed()=真。 – Buaban

回答

0

單擊按鈕

現在: -

 Boolean dropdownPresent = driver.findElement("YOUR LOCATOR OF DROPDOWN").isDisplayed(); 

     if(dropdownPresent==true) 
     { 
      System.out.println("Dropdown is appearing"); 
     } 
     else{ 
      System.out.println("Dropdown is not appearing"); 
     } 

希望它會幫助你:)

0

你問驗證整個場景。您需要先了解Selenium-WebDriver是什麼。有關更多說明,請參閱this教程。

但是你可以按照下面的代碼,

要驗證元素存在或無法使用此方法

public boolean isPresent(String locator) { 
    return findElements(locator).size() > 0 ? true : false; 
} 
0
  1. 首先收集列出所有下拉值,列表值=上傳假期#刪除假期
  2. 然後單擊下拉WebElement,使用DropdownFieldName = driver.findElement(by.xpath(//button[@class='button ng-binding'])).click();
  3. 採取下拉值的同時,drptotalCount = driver.findElements(by.xpath(//a[@class='button ng-binding']));
  4. 現在您已經預計DropDown值和Dropdown值的計數。

您可以從下面的代碼需要一個參考:

checkDropDownValues(String DropdownFieldName, String values){ 
     driver.findElement(By.xath(DropdownFieldName)).click(); 
     WebElement drptotalCount = driver.findElements(by.xpath(//a[@class='button ng-binding'])); 
     int numberOfDropDown = drptotalCount.size(); 
     List<String> allDropDownValues = Arrays.asList(values.split("#")); 
for (int colCount = 1; colCount <= numberOfDropDown; colCount++) { 
     boolean flag = false; 
     Actualvalue = driver.findElement(By.xpath(drptotalCount + "[.=" + allDropDownValues.get(colCount) +"]"])).getText(); 
String expectedValues = allDropDownValues.get(colCount); 
     if(expectedValues.equalIgnoreCase(Actualvalue)) 
     { 
       flag = true; 
     } 
Assert.assertTrue("Column values doesn't match", flag); 
} 
} 
0
  1. 點擊按鈕(這應該是直線前進)
    • 看來你有一些異步調用或延遲
  2. 等待下拉菜單'div.hpDropDownButton'is beei 。

    WebElement myDynamicDropDown =(新WebDriverWait(驅動程序,10)),直到(ExpectedConditions.presenceOfElementLocated(By.CssSelector( 「div.myDynamicDropDown」)))

  3. 繼續..

  4. :使用WebDriverWait納克顯示

http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp