This question is locked. New answers and comments are not allowed.
I'm trying to find a way to attach a javascript file to a loaded webpage using code in my test project. Essentially I have some javascript helper methods that I need to be present on the webpage so I can run certain tests. Ideally I do not want to have to adjust my web application to include a reference to the helper .js file on the page, instead I would rather my test attach it when it needs it. Is this conceivably possible?
Using Actions.InvokeScript() it is possible to send a string of javascript to the browser. As such I tried the following
The InvokeScript() method reports an error when executing the 4th command i.e. the appendChild() line. If you run the javascript directly in the browser (e.g. from behind a button), it works fine, and you immediately have access to all the methods exposed by helper.js, so the problem is not the javascript.
Does anyone know a way of injecting javascript into a page via the webaii framework?
Using Actions.InvokeScript() it is possible to send a string of javascript to the browser. As such I tried the following
| string js = @"{ var fileref = document.createElement('script'); |
| fileref.setAttribute('type', 'text/javascript'); |
| fileref.setAttribute('src','file:///C:/Temp/helper.js'); |
| document.getElementsByTagName('head')[0].appendChild(fileref); |
| }"; |
| ActiveBrowser.Actions.InvokeScript(js); |
The InvokeScript() method reports an error when executing the 4th command i.e. the appendChild() line. If you run the javascript directly in the browser (e.g. from behind a button), it works fine, and you immediately have access to all the methods exposed by helper.js, so the problem is not the javascript.
Does anyone know a way of injecting javascript into a page via the webaii framework?