I have create a JQuery script that works in the browser console, but it is not working in the selenium3 automation. The exception I'm receiving is unknown error: $ is not defined
. I read that the problem is the second argument in the selector. I have tried to escape the $
character but it is not working.
This is the excript I have executed in the browser console:
$('input[type=file]', $('#fonto').contents()).css('display','block')
But when I executed during my test case, is not working. This is the line of code:
((JavascriptExecutor) getDriver()).executeScript("$('input[type=file]',
$('#fonto').contents()).css('display','block')");
I need the second argument because the input is inside an iframe.
This problem occurs in firefox and chrome browsers.
Which is the proper way to execute this script?
EDIT The JQuery is not loaded. I need to know how to enable the JQuery before execute my script.
Firstly you should switch to iframe. Than include jquery like this:
You can execute your jquery code now. If you have nested iframes you should configure code again.