2016-07-04 56 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

如果你认为这有帮助请给大拇指! –