2012-01-17 4 views
1

나는 WatiN을 사용하고 있습니다. 우리 회사는 jQuery show and hide 함수를 사용하여 오류 메시지를 표시합니다. 이 메시지가 정확한 시간에 나타나는지 확인하고 싶습니다. 나는 show와 hide를 사용하는 jQuery 다운로드에서 테스트 스크립트를 사용했다. id 값을 div 태그 및 포함 된 스캔 태그 중 하나에 추가했습니다. 메시지가 표시 될 때 내 코드에서 감지 할 수 없습니다.WatiN을 jQuery show and hide 기능과 함께 사용하려면 어떻게해야합니까?

아래에 jQuery 스크립트와 내 코드가 모두 포함되어 있습니다. 스크립트에는 표시 용과 메시지 숨김 용의 두 가지 단추가 있습니다. 내 코드는 숨기기 단추를 누르고 가시성 및 너비 특성을 검사 한 다음 표시 단추를 누르고 동일한 특성을 조사합니다. 나는 그 텍스트가 정말로 숨겨져 있고 보여지고 있다는 것을 화면에서 볼 수있다. 중단 점을 설정하면 두 경우 모두 가시성이 "상속"으로 설정되고 너비는 "자동"으로 설정됩니다. 두 경우를 구별하기 위해 무엇을 할 수 있습니까?

jQuery code: 
<!DOCTYPE html> 
<html> 
<head> 
     <style> 
     span { background:#D8BFD8; padding:3px; float:left; } 
     </style> 
     <script src="jquery-1.7.1.js" type="text/javascript"></script> 
    </head> 
<body> 
    <button id="hidb">Hide</button> 
    <button id="showb">Show</button> 
    <div id="dynamicOutput"> 

    <span id="jquery">jQuery</span> <span>is</span> <span>easy</span> 
    <span>to</span> <span>use</span> <span>and</span> 
    <span>gives</span> <span>dynamic output..</span> 

    </div> 

<script> 
    $("#hidb").click(function() { 
       $("span:last-child").hide("fast", function() { 
    // use callee so don't have to name the function 
     $(this).prev().hide("fast", arguments.callee); 
     }); 
    }); 
$("#showb").click(function() { 
    $("span").show(2000); 
}); 

</script> 
</body> 
</html> 

Test code: 

[TestMethod] 
     [STAThread] 
     public void lookAtElements() 
     { 

       var browser = new IE("http://localhost/test/jqHIdeShowText.html"); 

       Element el2 = browser.Span(Find.ById("jquery")); 
       Element el = browser.Div(Find.ById("dynamicOutput")); 

       string att; 
       string att2; 
       string width; 
       string width2; 
       string msg; 
       string msg2; 


       Button btn = browser.Button(Find.ById("hidb")); 
       btn.Click(); 


       width = el.Style.GetAttributeValue("width"); 
       width2 = el2.Style.GetAttributeValue("width"); 

       System.Threading.Thread.Sleep(5000); 

       el.Parent.Refresh(); 
       el.Refresh(); 
       el2.Refresh(); 

       width = el.Style.GetAttributeValue("width"); 
       width2 = el2.Style.GetAttributeValue("width"); 
       att = el.Style.GetAttributeValue("visibility"); 
       att2 = el2.Style.GetAttributeValue("visibility"); 
       msg = el.Text; 
       msg2 = el2.Text; 


       btn = browser.Button(Find.ById("showb")); 
       btn.Click(); 
       System.Threading.Thread.Sleep(5000); 

      el.Parent.Refresh(); 
      el.Refresh(); 
      el2.Refresh(); 

       att = el.Style.GetAttributeValue("visibility"); 
       att2 = el2.Style.GetAttributeValue("visibility"); 
       width = el.Style.GetAttributeValue("width"); 
       width2 = el2.Style.GetAttributeValue("width"); 
       msg = el.Text; 
       msg2 = el2.Text; 

       browser.Close(); 


      } 

답변

0

대신 display 속성을 테스트 해보십시오 : 당신의 응답을

if (el.Style.GetAttributeValue("display") == "none") { 
    // The element was hidden through hide(). 
} 
+0

감사합니다. 이를 위해 필자는 오류 메시지가 입력 필드와 연관되어 표시되는지 확인해야했습니다. 오류 메시지가있는 경우 입력 필드의 상위 항목에 오류 메시지가 포함 된 텍스트 상자가 있고 오류가없는 경우 텍스트 상자가 없었습니다. – user1153980

+0

우수 :) 이제는 자신의 답변에 관련 부분을 게시해야합니다 (적합하다고 생각되는대로 약간 정교하게 다듬은 후). [이 상황에서 허용되고 실제로 권장됩니다.] (http://meta.stackexchange.com/questions/17463/can-i-answer-my-own-questions-even-those-where-i-knew-the- 대답하기 전에). –