2011-09-07 2 views
1

저는 지난 6 개월 동안 WebDriver를 사용해 왔습니다.Regd : WebDriver on secure 인증서

이 문제의 몇 지금 바로 [버전 2.3.1]에 직면하고 있습니다

가) 내가 보안 인증서에 대한 재정의 링크 요소를 취득 할 때 [HTTPS] IE에서 페이지를 통해 webdriver findElement , 그 요소를 찾을 수 있지만 셀레늄 RC 잘 작동합니다.

그렇다면 다음을 사용하여 tht 수정 사항을 얻었습니다. webDriver.navigate(). (javascript : document.getElementById ('overridelink'). click());

참고 : 나는 보안 인증서 페이지의 요소를 가져 오기 위해 아래의 코드를 사용했지만, 그것은 초점 body 요소

WebElement activeElement() [WebElement, 또는 신체의 요소없는 요소 경우를 반환 포커스가 감지 될 수 있습니다.], 왜 findelement를 사용하여 요소를 선택할 수 없습니까?

b) webdriver 테스트를 실행하기 위해 SSL을 통해 원격 네트워크에 연결되어 있는데 보안 인증서 [https] 페이지에서 무시 링크를 클릭 할 수 없습니까?

c) jbehave와 같은 프레임 워크를 사용하는 대신 webdriver를 구현하는 것이 더 좋습니다 (현재이 방법을 사용하고 있습니다)?

제안 감사합니다, 자야 라즈

답변

0

그래, 내가 가진 유사한 문제를 알려주십시오. 어떤 이유로 Webdriver가
인증서 오류 페이지에 대한 완전한 정보를 갖고 있지 않은 것 같습니다.
이 (도움말, 나는 여전히 코드의 형식을 마크 다운을 freeeking 얻을 수 없습니다 내가 인증서 오류 페이지를 해결하기 위해이 해킹을 사용하고
파이썬/Webdriver와 IE 7을 실행 나는 윈도우 XP SP3에있어
, 블록 ...)


#!/c/Python27/python 

import win32con 
import win32gui 

def certificate_continue(): 
    """ 
    Find the IE Window that has a Certificate Error and try to continue anyway. 
    We'll use the win32 modules to find the right window & child window, 
    then write some Javascript into the address bar and execute to continue. 
    """ 
    def _enumWindowsCallback(hwnd, windows): 
     """ 
     Cannibalized from Gigi Sayfan (WindowMover) 
     http://www.devx.com/opensource/Article/37773/1954 
     This appends window information as a 3-tuple to the list 
     passed into win32gui.EnumWindows() 
     """ 
     class_name = win32gui.GetClassName(hwnd) 
     # apparently win32gui.GetWindowText() only works to get the text 
     # on a button or a label not really for edit windows. 
     text = win32gui.GetWindowText(hwnd) 
     windows.append((hwnd, class_name, text)) 


    def _get_certificate_error_window(): 
     """ 
     all_windows[] gets filled up with a list of tuples, then loop through 
     it filtering on class and the window text (title bar text). 
     Assumes only one 'Certificate Error' window. 
     """ 
     all_windows = [] 
     win32gui.EnumWindows(_enumWindowsCallback, all_windows) 
     for win in all_windows: 
      class_name = win[1] 
      title_bar_text = win[2] 
      if class_name == 'IEFrame' and \ 
        'Certificate Error: Navigation Blocked' in title_bar_text: 
       return win 

    def _get_edit_text(hwnd): 
     """ 
     This function courtesy of Omar Raviv with huge help from Simon Brunning. 
     http://www.brunningonline.net/simon/blog/archives/000664.html 
     """ 
     buf_size = win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0) 
     buf_size += 1 # don't forget that null character boys... 
     buffer = win32gui.PyMakeBuffer(buf_size) 
     # odd, we're telling them how big the text is that they're giving 
     # back to us 
     win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, buf_size, buffer) 
     # don't need the null character now for Python 
     return buffer[:buf_size] 


    def _get_address_bar(parent_handle): 
     """ 
     There appears to be several 'Edit' windows within each browser window. 
     From Microsoft: If a child window has created child windows of its own, 
     EnumChildWindows enumerates those windows as well. 
     """ 
     childwins = [] 
     win32gui.EnumChildWindows(parent_handle, _enumWindowsCallback, 
            childwins) 
     for win in childwins: 
      child_handle = win[0] 
      class_name = win[1] 
      if 'Edit' in class_name: 
       edit_text = _get_edit_text(child_handle) 
       if 'http://' in edit_text or 'https://' in edit_text: 
        return child_handle # then this must be it... 


# begin certificate_continue 
    target_win = _get_certificate_error_window() 
    try: 
     cert_err_handle = target_win[0] 
    except TypeError: 
     print "OK, no Certificate Error window available" 
     return(1) 

    address_bar_handle = _get_address_bar(cert_err_handle) 
    # any better way to check the handle ? 
    if not win32gui.IsWindow(address_bar_handle): 
     print "Choked getting IE edit window" 
     return(1) 

    # now, need to send this JavaScript text to the browser Address Bar 
    javascript_continue = 'javascript: var continue_element = document.getElementById("overridelink"); continue_element.click();' 
    win32gui.SendMessage(address_bar_handle, win32con.WM_SETTEXT, 0, 
         javascript_continue) 

    # OK, and finally, send a carriage return to the address bar 
    # This last abomination, courtesy of Claudiu 
    # http://stackoverflow.com/#questions/5080777/ 
    # what-sendmessage-to-use-to-send-keys-directly-to-another-window 
    win32gui.SendMessage(address_bar_handle, win32con.WM_KEYDOWN, 
         win32con.VK_RETURN, 0) 
    return(0) 


if __name__ == '__main__': 
    status = certificate_continue() 
    exit(status) 
+0

방법이 사용합니까을? 나는 webdriver를 SSL URL로 가져 가고 'Certificate Error : Navigation Blocked'페이지가 나타납니다. 페이지를 처리하려면 어떻게해야합니까? – amadain

2

가 해결 주셔서 감사합니다!

자바를 들어, 솔루션은 조금 다를 것 그리고 그것은 나를 도와 :

//driver is initialised somewhere before, for example, as RemoteWebDriver  
driver.navigate().to("javascript:document.getElementById('overridelink').click()"); 
+0

이것은 C#에서도 작동합니다. – TheJediCowboy