2016-12-19 4 views
0

4 행 4 열의 테이블이 있습니다. 마지막 두 열에는 두 개의 단추가 있습니다. 시작취소. 두 번째 행/마지막 열의 취소 버튼을 누릅니다. 각 행의 코드는 비슷합니다 ... 시작하려는 서비스 이름을 뺀 것입니다.Follow-Sibling을 사용하여 테이블 안의 버튼을 클릭하십시오. PYTHON

행 1 장난감 서비스 1

행 2 장난감 서비스 2

행 3 장난감 서비스 3 :

<table class="table"> 
    <tbody> 
     ---this is the first row--- 
     <tr ng-repeat="toyService in theService" ng-class="{'text-muted':toyservice.notFound" class="ng-scope"> 
     --- this is the second row.. the row I am trying to start---- 
     <tr ng-repeat="toyService in theService" ng-class="{'text-muted':toyservice.notFound" class="ng-scope"> 
      <td style="text-align:center">...</td> 
      <td class="ng-binding"> Toy Service 2 </td> 
      <td class="ng-binding">...</td> 
      <td class="toy-service-button-panel text-right"> 
       ----the first button (Start Button) 
       <button type="submit" class="btn btn-info">...</button> 
       ----the button I am trying the click (Cancel) 
       <button type="submit" class="btn btn-success btn-sm" 
        <span title="Cancel Service">..</span> 

각 행은 동일한 코드를 뺀 서비스 이름이

행 4 내가 뭘하려 장난감 서비스 4

했다 :

driver.find_element_by_xpath("//td[contains(text(), 'Toy Service 2')]/follow-sibling::td").find_element_by_css_selector("td[class='toy-service-button-panel.text-right']").find_element_by_css_selector("button[class='btn.btn-success.btn-sm']").click() 

내가

이 문서 '에 대한 평가'실행하지 못했습니다라는 오류 얻을 : 문자열 // TD를 [포함 (text(), Toy Service 1 ')]/follow-sibling :: td'는 유효한 XPath 표현식이 이 아닙니다.

driver.find_element_by_xpath("//td[contains(text(), 'Toy Service 2')]/following-sibling::td") 

, 나는 '돈 :

나는 다른 방법을 시도했다하지만 난 행에이 취소 버튼을 클릭 할 수없는 것 2

답변

1

그것은, 그것은 following-sibling하지 follow-sibling한다 following-sibling::td<td class="ng-binding"> Toy Service 2 </td> 다음에 바로 다음 td 요소와 일치하며 원하는 단추가 포함되어 있지 않으므로 사용자의 접근 방식이 효과가 있다고 생각하지 마십시오.

대신, 내가 처음 작업 할 tr 요소 알아낼 것이다 : 그런 다음

row = driver.find_element_by_xpath("//tr[td[contains(., 'Toy Service 2')]]") 

을,이 행 내에서 작동 할 것입니다 :

row.find_element_by_css_selector("td.toy-service-button-panel button.btn.btn-success").click() 

또한 단순화 한 우리의 선택자 조금, 완전한 class 속성 값을 확인할 필요가 없습니다 - 점 표기법으로 개별 클래스를 확인할 수 있습니다.

+0

감사합니다. 이것은 더 잘 작동합니다. – royalblue