0

셀레늄 웹 드라이버를 사용하여 나에게 내가 CSS 선택기를 사용하여 이러한 요소를 얻기 위해 노력했다검도 UI 드롭 다운 값 선택 - 셀레늄

등 등 지난 30 일 같은 옵션 값의 집합을 얻을 필요가 최근 60 일 .

var timeperiodcss = "div.k-animation-container div.k-list-container.k-popup.k-group.k-reset div ul#selectDefaultTimePeriod li.k-item"; 
       var elements = element.FindElements(By.CssSelector(timeperiodcss)); 
       if (elements.Count >= 1) 
        break; 

elements.count가 0으로 표시 될 때마다 해당 요소를 가져올 수 없습니다. 206px; 여백 왼쪽 : -10px; 패딩 왼쪽 : 10px; 높이 150 픽셀 :

다음 이러한 경우

DIV 클래스 = "K-애니메이션 용기"스타일 = "너비 HTML 콘텐츠입니다 오른쪽 : 10px, 아래쪽 패딩 : 15px, 상자 크기 : 내용 상자, 오버플로 : 숨김, 표시 : 없음, 위치 : 절대, 위쪽 : 1039.55px, z- 인덱스 : 10002, 왼쪽 : 87.45px, >

<div id="selectDefaultTimePeriod-list" class="k-list-container k-popup k-group k-reset" data-role="popup" style="position: absolute; height: 200px; display: none; font-size: 13px; font-family: "Roboto",sans-serif; font-stretch: normal; font-style: normal; font-weight: 400; line-height: 18px; width: 144px; transform: translateY(204px);"> 
<div class="k-list-optionlabel">Select time period</div> 
<div class="k-group-header" style="display:none"></div> 
<div unselectable="on" style="overflow: auto; position: relative; height: 175px;"> 
<ul id="selectDefaultTimePeriod_listbox" class="k-list k-reset" unselectable="on" tabindex="-1" aria-hidden="true" aria-live="off" data-role="staticlist" role="listbox"> 
<li class="k-item" data-offset-index="0" unselectable="on" role="option" tabindex="-1">Last 30 days</li> 
<li class="k-item" data-offset-index="1" unselectable="on" role="option" tabindex="-1">Last 60 days</li> 
<li id="0936dfb5-4f8c-4dd4-826f-f802b6a719ff" class="k-item k-state-selected k-state-focused" data-offset-index="2" unselectable="on" role="option" tabindex="-1">Last 90 days</li> 
<li class="k-item" data-offset-index="3" unselectable="on" role="option" tabindex="-1">Last month</li> 
<li class="k-item" data-offset-index="4" unselectable="on" role="option" tabindex="-1">Last quarter</li> 
<li class="k-item" data-offset-index="5" unselectable="on" role="option" tabindex="-1">Last 6 months</li> 
<li class="k-item" data-offset-index="6" unselectable="on" role="option" tabindex="-1">Last 12 months</li> 
<li class="k-item" data-offset-index="7" unselectable="on" role="option" tabindex="-1">Last 365 days</li> 
<li class="k-item" data-offset-index="8" unselectable="on" role="option" tabindex="-1">Full year 2016</li> 
</ul> 
</div> 
</div> 

알려 주시기 바랍니다. 다른 옵션도 있습니다.

+0

대기 시간을 올바르게 사용하여 로딩 시간을 처리하셨습니까? –

답변

0

xpath를 두 단계로 사용하여 이러한 요소를 선택할 수 있습니다.

1 단계 : 드롭 다운을 클릭하십시오. // 드롭 다운을 클릭 한 후 드롭 다운 목록의 html 만 볼 수있게되므로이 작업을 수행해야합니다.

코드 : driver.findElement (By.id ("selectDefaultTimePeriod_listbox")). click();

2 단계 : xpath를 사용하여 li 요소를 선택하십시오.

코드 : drive3r.findElement (By.xpath ("// ul/li [text() = '지난 30 일']));