학습자 :
나는 지금 내가 봄 토글 체크 박스를 클릭합니다 나타내는 지정된 인덱스 위치 말 (1)와 리 요소를 전환 할 수 셀레늄 I 개미를 사용하여이 HTML을 가지고있다.
<ul id="todo-list" data-woven="abc">
<li class="active" data-index="0">
<div class="view">
<input class="toggle" type="checkbox">
<label>Java</label>
<button class="destroy"></button>
</div>
<input class="edit">
</li>
<li class="active" data-index="1">
<div class="view">
<input class="toggle" type="checkbox">
<label>Spring</label>
<button class="destroy"></button>
</div>
<input class="edit">
</li></ul>
나는 우리가 이것을 달성 할 수있는 방법을 이해 그렇게 할 수없는 셀레늄 완전히 새로운입니다.
내가 얻을 알고 UL
코드를 사용하여 요소를 :
driver.findElement(By.id("todo-list"));
지금 얻을 수있는 방법 li
의 기반으로 요소 index
와 click
대응을 checkbox
.
DebanjanB :
온 클릭 체크 박스 조상에 대한 요소 것은 <li>
노드 인덱스 는 다음 중 하나를 사용할 수있는 속성 로케이터 전략 :
cssSelector :
driver.findElement(By.cssSelector("ul#todo-list li.active[data-index='1'] input")).click();
XPath는 :
driver.findElement(By.xpath("//ul[@id='todo-list']//li[@class='active' and @data-index='1']//input")).click();