2016-07-06 11 views
0

私はソースでこの部分を持っている:cssSelectorまたはxPath Selenium Webドライバでフィルタにボタンを適用しますか?

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

そして、私のJavaの部分はこのようなものです:

// detect type of the filter 

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']//span[@class='label'][text()='Apply']/..")).size() > 0) { 
       type = "multi_checkbox_with_apply"; 
      } 
      else { 
       type = "multi_checkbox_without_apply"; 
      } 
     } 
    } 

//if apply button enabled 
      element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='"+id+"_menu']//div[@class='CFApplyButtonContainer']//span[@class='label'][text()='Apply']/.."))); 
      if (element.getAttribute("disabled") == null) { 
      element.click(); 
      //log("clicked on apply button"); 
      waitForLoadingSpinner(); 
     } 
     else { 
      //log("apply button disabled - no need to click on it"); 
     } 

     // close drop down menu 
     element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='tab-glass clear-glass tab-widget']"))); 
     element.click(); 
     //log("dropdown menu closed"); 
    } 

は、「適用」が含まスパンを見つけるために、この正しい方法ですか?私の応募は突然止まり、何を試すのか分からないのですか?

答えて

2

Aタグにのみ適用されるリンクテキストを検索する以外に、タグ内のテキストを検索する唯一の方法は、XPathを使用することです。以下はあなたが望むものを得るはずです。

//div[@class='CFApplyButtonContainer']/button/span[text()='Apply'] 

、あなたの質問

if (driver.findElements(By.xpath("//div[@class='CFApplyButtonContainer']/button/span[text()='Apply']")).size() > 0) 
{ 
    // found the element, do stuff 
} 
+0

こんにちはで行ったようにこれを使用するには、ヘルプのおかげしかしときに私は、この置く:(driver.findElements(By.xpath( "// divの[@class場合をsize()> 0)それはちょうど停止し、何もしません、何とかこのsize()> 0でクリックしたくない適用ボタン。私は何をすべきかわからない – marija

+0

上記のif文はクリックしないので、他の場所をクリックしていると仮定していますか?あなたが提供したHTMLがあれば、このXPathが動作します。あなたがあなたの質問に表示されているように、それにものを追加する場合は、私はそこにあなたが多くの情報なしでお手伝いをすることはできません。 – JeffC

+0

こんにちは、あなたのソリューションは動作しています、ちょうど私が一点でフィルタリングに問題があり、その部分をスキップする方法を知らない。しかし、ありがとう! – marija

関連する問題