2016-07-04 29 views
1

我有應用按鈕的問題。我有組合框過濾器,一切都很好,它是在square之間切換的。但是當它想要應用時,不知何故,它只是繼續,因爲它沒有被選擇任何東西,並且測試成功完成,但沒有我需要的過濾。Selenium應用按鈕無法在組合框上工作?

有人可以用檢查器錯誤檢查我的代碼和部分。也許我錯過了什麼?

我的Java代碼:

if (type.equals("")) { 

elementList = driver.findElements(By.xpath("//div[@id='" + id + "_menu']//a[@class='FIText']")); 

    if (elementList.size() > 0) { 

     if (driver.findElements(By.xpath("//div[@id='" + id + "_menu']//div[@class='CFApplyButtonContainer']//button[@class='tab-button']//span[@class='label'][text()='Apply']/..")).size() > 0) { 

      type = "multi_checkbox_with_apply"; 
     }else { 
      type = "multi_checkbox_without_apply"; 
     } 
    } 
} 

檢查錯誤:

<div class="CFApplyButtonConatiner" style="height: 21px;"> 
<button class="tab-button tab-widget disabled" type="button" style="max-width: 56px" disabled=""> 
<span class="icon"></span> 
<span class="label">Cancel</span> 
</button> 
<button class="tab-button tab-widget focus disabled" type="button" style="max-width: 56px" disabled=""> 
<span class="icon"></span> 
<span class="label">Apply</span> 
</button> 

有人可以檢查此嗎? 我不知道爲什麼它不工作?也許有人知道如何測試它。

BR, Marija的

回答

2

只要是明確的,該解決方案將尋找元件,其顯示,它會點擊它!

WebDriverWait wait = new WebDriverWait(driver, 10); 
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.CFApplyButtonConatiner")))); 
List<WebElement> elementsList = driver.findElements(By.cssSelector("div.CFApplyButtonConatiner > button"); 
for(WebElement ele: elementsList) { 
    if(ele.isDisplayed()) { 
     ele.click(); 
    } 
} 
0

我用像Ranijth的建議:

if (type.equals("")) { 
     elementList = driver.findElements(By.xpath("//div[@id='" + id + "_menu']//a[@class='FIText']")); 

     if (elementList.size() > 0) { 


      //if (driver.findElements(By.xpath("//div[@id='" + id + "_menu']//div[@class='CFApplyButtonContainer']//button[@class='tab-button']//span[@class='label'][text()='Apply']/..")).size() > 0) { 


        if (driver.findElements(By.cssSelector("div.CFApplyButtonConatiner > button"))!=null) { 

      //if (driver.findElements(By.cssSelector("div.CFApplyButtonConatiner > button")).size() > 0) { 


      type = "multi_checkbox_with_apply"; 
      } 
      else { 
       type = "multi_checkbox_without_apply"; 
      } 
     } 
    } 

現在它工作正常,但現在我需要對其進行測試,以檢查輸出。如果有人有更好的解決方案,請告訴我。

+0

如果你認爲這有幫助請給大拇指! –