I am trying to execute a javascript file through webdriver in C#. The following is what i have so far:
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
(string)js.ExecuteScript("var s = window.document.createElement(\'script\'); s.src = \'E:\\workspace\\test\\jsPopup.js\'; window.document.head.appendChild(s); ");
js.ExecuteScript("return ourFunction");
The content of jsfile.js are
document.ourFunction = function(){ tabUrl = window.location.href;
imagesPath = chrome.extension.getURL("images");
var optionsPopupPath = chrome.extension.getURL("options.html");
}
However when i execute
js.ExecuteScript("return ourFunction");
It throws an exception of ourFunction not found. What i want to do is run a complete javascript file through js injection or any other method that would let me access the data generated by the js file. Any help ?