2016-07-06 1 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> 

을 그리고 내 자바 부분은 다음과 같이이다 :

// 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

관련 문제