2013-07-08 9 views
0

Ruby와 함께 Selenium WebDriver를 사용하여 자동화 된 스크립트를 작성하고 있습니다. 경우에, 나는 '취소'버튼을 클릭했는데 다음은 그것을위한 HTML 코드입니다 : 여기'취소'버튼을 클릭 할 수 없습니다.

driver.find_element(:xpath, "//button[@class='cancelButtonClass']").click 

: '취소'버튼을 클릭 들어

<div class="ui-dialog-buttonset"> 
<button class="otherButtonClass" type="button" role="button" aria-disabled="false"> 
    <span class="ui-button-text">Rename</span> 
</button> 
<button class="cancelButtonClass" type="button" role="button" aria-disabled="false"> 
    <span class="ui-button-text">Cancel</span> 
</button> 
</div> 

, 나는 다음과 같은 썼다 클릭 동작이 발생하지 않습니다. 나는 잠을 자려고 노력했다. } 여전히 문제가 해결되지 않았습니다.

driver.find_element(:xpath, "//button[@class='otherButtonClass']").click 

나에게 이유를 이해하는 데 도움이 바랍니다 : 발생 된 오류가 작동, '요소가 보이지 따라서 상호 작용 할 수 없습니다'나는 '이름 바꾸기'버튼에 대한 조치를 클릭하여 수행하는 경우,

그러나입니다 이 일이 일어나고 있습니다. 나는 'Rename'과 'Cancel'이 비슷한 HTML 코드를 가지고 있고 'Rename'을 클릭하고 'Cancel'을 클릭하는 것은 혼란 스럽다. 왜 이런 식으로?

답변

0

당신은 아래에 시도 할 수 있습니다 :

script = <<-end 
element = arguments[0]; 
element.setAttribute('aria-disabled','true'); 
return element; 
end 

# select the 'Cancel' button element 
elem = driver.find_element(:css,'div.ui-dialog-buttonset>button')[1] 
# setting the 'aria-disabled' to true 
elem = driver.execute_script(script,elem) 
#after enabling the css attribute 'aria-disabled' click on the 
#cancel button 
elem.click 
0

버튼의 CSS는 어떤 호버 행동에 대한 동적 경우 경우에 완벽한 해결책이 될 수 없습니다 CSS 선택을 사용. 또한 주어진 요소를 선택하는 간단한 방법은 다음 xpath를 사용하는 것입니다.

driver.find_element(:xpath, "//span[text()='Cancel']").click 
+0

예, 동의합니다. 버튼의 CSS가 동적 인 경우에만 해결책을 제안했습니다. – Karthikeyan

관련 문제