I want execute following javascript code …Please help on this
var coverage = “NIGHT”;
var grade = “NM”;
var date = “May 21”
var coverageId = $("#div_2_1 .divTableRow .divCoverageBorderTop:contains(’"+coverage+"’)").attr(“data-coverage-id”);
var gradeId = $("#div_2_1 .divTableRow .divTableCell[data-coverage-id=’"+coverageId+"’]:contains(’"+grade+"’)").attr(“data-grade-id”);
var date = $("#div_1_2").find(".divTableCell:contains(’"+date+"’)").attr(“data-date”);
$(".divTableCell[coverageid=’"+coverageId+"’][gradeid=’"+gradeId+"’][datetime=’"+date+"’]").click();
Sorry, that’s broken JavaScript.
Assuming your JavaScript is fixed and working…
//This is a groovy TRIPLE-QUOTED string, NOT a typo. Place this in your Groovy code.
String js = '''
first line of js;
second line of js;
another line of js;
return result; // this is how to return a result from javascript
''' // end of groovy triple-quoted string
// call the javascript from groovy AND collect the result
def result = WebUI.executeJavaScript(js, null)
Worked example…
String js = '''
var a = 1;
var b = 2;
return a + b;
'''
int result = WebUI.executeJavaScript(js, null)
println result