2014-08-29 92 views
0

我想在我的實習生/ selenium/leadfoot測試正在運行的客戶端瀏覽器中執行javascript。具體來說,我試圖繞過IE8 & 9證書警告。Leadfoot繞過IE證書警告

以前,使用硒-python綁定,我可以使用此代碼在所有瀏覽器上運行,通過警告,如果它發生了:

if "Certificate" in driver.title: 
    driver.get("javascript:document.getElementById('overridelink').click();") 

現在使用leadfoot,我已經試過以下的多種組合:

.get(require.toUrl('https://secure-url.com') 
.execute("document.getElementById('overridelink').click();") 
// OR 
.get("javascript:document.getElementById('overridelink').click();") 

但無法獲得此JavaScript在客戶端上執行。有沒有人有過這個成功?

.execute('alert("hello");') 

可以在其他頁面上正常工作,但不能在此頁面上正常工作。就好像leadfoot無法在此安全頁面中運行JS,但是selenium api是?

最終失敗,出現錯誤:

JavaScriptError: [POST http://localhost:4444/wd/hub/session/1fa8a4a3-8774-46af-ad87-0e8fbc5a1388/execute/{"script":"document.getElementById('overridelink').click();","args":[]}] JavaScript error (WARNING: The server did not provide any stacktrace information) 

Command duration or timeout: 30 milliseconds 

Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03' 

System info: host: 'IE9Win7', ip: '169.254.0.207', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_67' 

Session ID: 8b20796a-1d40-48ad-82e1-25ce16a40f17 

Driver info: org.openqa.selenium.ie.InternetExplorerDriver 

Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=9, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=http://localhost:29797/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}] 

    at Server._post <node_modules\intern\node_modules\leadfoot\Server.js:68:9> 
... 

另外,我可以在WebDriverIO確認我可以繞過警告:

client.url("javascript:document.getElementById('overridelink').click();") 
+0

你什麼錯誤? – Louis 2014-08-30 10:32:12

+0

它爲下面的'''.find()''語句提供了超時錯誤,似乎是在錯誤的上下文中執行的。 – lacy 2014-08-31 19:28:37

+0

在您的問題中顯示find語句以及您所得到的確切錯誤消息將是一件好事。另外,你是否檢查瀏覽器上的控制檯,看看是否有錯誤? – Louis 2014-08-31 20:46:19

回答

0

我能夠順利通過證書錯誤頁面導航通過發送按鍵,通過頁面選項卡覆蓋鏈接並輸入像這樣:

.pressKeys([Keys.TAB, Keys.TAB, Keys.TAB, Keys.ENTER]) 

顯然可能有更好的方法,但是這個工作。

例子:

 var command = this.remote; 
     return command 
      .get(require.toUrl('https://portal-stg.vpc.locusdev.net')) 
      .getPageTitle() 

      // IE Certificate Error Workaround 
      .then(function(title) { 
       if (title.indexOf('Certificate Error') !== -1) { 
        command.pressKeys([Keys.TAB, Keys.TAB, Keys.TAB, Keys.ENTER]) 
       } 
       return true; 
      })