My current challenge involves executing JavaScript in the browser of the client where my intern/selenium/leadfoot tests are running. Specifically, I am attempting to bypass the certificate warning on IE8 & 9.
In the past, using selenium-python bindings, I was able to use the following code to handle the warning if it appeared:
if "Certificate" in driver.title:
driver.get("javascript:document.getElementById('overridelink').click();")
Now, with leadfoot, I have experimented with various combinations like:
.get(require.toUrl('https://secure-url.com')
.execute("document.getElementById('overridelink').click();")
// OR
.get("javascript:document.getElementById('overridelink').click();")
However, I am unable to successfully execute this JavaScript on the client. Has anyone managed to achieve this?
.execute('alert("hello");')
This works fine on other pages, but not on this particular page. It seems like leadfoot is restricted from running JS on this security page, unlike the selenium API.
Eventually, it results in the following error:
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>
...
I can also confirm that WebDriverIO allows me to bypass the warning using the following code snippet:
client.url("javascript:document.getElementById('overridelink').click();")