I'm fairly new to using Selenium. I have come across this javascript code snippet and I am attempting to use Selenium to inspect the script, but I haven't had much luck so far. My main goal is to employ Selenium to access/inspect the script in order to confirm that it exists on my page.
This is the anonymous function in question:
<script type="text/javascript">
(function(a,b,c,d){
a='https://someurl.com:24800/somejs.js';
b=document;
c='script';
d=b.createElement(c);d.src=a;d.type='text/java'+c;
d.async=true;
a=b.getElementsByTagName(c)[0];
if (a.src !== d.src) {
a.parentNode.insertBefore(d,a);
}
})();
</script>
To illustrate the issue further, in another instance I've managed to retrieve a piece of javascript assigned to a variable like this:
<script type="text/javascript">
var my_var = { attribute_1:'something', attribute_2:'somethingElse'}
</script>
Then, within my Selenium test...
JavascriptExecutor jsEx = (JavascriptExecutor) driver;
Map<String, String> topScript = (Map<String, String>)jsEx.executeScript("return my_var");
The above code works smoothly and allows me to extract the script for parsing. I'd like to achieve the same result with the anonymous function mentioned earlier (if possible).
I have already attempted to find solutions in the following posts, but without success:
Selenium calling anonymous function generates syntax error
Selenium and asynchronous JavaScript calls