我试图在我的实习生/ selenium / leadfoot测试运行的客户端的浏览器中执行javascript。具体来说,我试图绕过IE8& amp; 9证书警告。
以前,使用selenium-python绑定我可以使用此代码在所有浏览器上运行,如果发生则传递警告:
if "Certificate" in driver.title:
driver.get("javascript:document.getElementById('overridelink').click();")
现在使用铅笔,我尝试了以下几种组合:
.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 :(得分: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;
})