My JavaScript code is causing some issues when executed with Selenium's JavascriptExecutor
. Strangely, the code returns null
through Selenium but a value in Firefox developer console.
function temp(){
var attribute = jQuery(jQuery("[name='q']")[0]).attr('type');
if(typeof attribute !== 'undefined' && attribute !== false){
return attribute;
} else {
return '';
}
}
temp();
Here's my WebDriver code using the same JS function:
JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;
Object inputType =
jsExecutor.executeScript("function temp(){...}temp();");
System.out.println("Type: " + inputType);
Instead of getting the expected "text" string, I'm only getting null
. Any ideas on what could be causing this?