I am working with a website and I need to run a couple js code with Selenium. To make things easier, I need to run functions declared in the website scripts.
For example, the website use a script file called document_handler.js
with the following code:
(function ($) {
var getConversationId = function(){
return $('input[name="conversationId"]').val()
};
})(jQuery);
In Selenium, if I run:
js_eval = driver.execute_script("return getConversationId()")
I get:
selenium.common.exceptions.WebDriverException: Message: getConversationId is not defined
And if I run:
js_eval = driver.execute_script("return $.getConversationId()")
I get:
selenium.common.exceptions.WebDriverException: Message: $.getConversationId is not a function
How can I load the website javascript files so I can use its functions inside Selenium? Or there is something wrong with my code?