I am trying to run a script using executeAsyncScript() method having a fetch call. since fetch call returns a promise, hence on console it is taking some time to fulfill the promise but using selenium java script executer it is throwing error saying script time out,hence I am getting null as output. how can I achive the expected result using selenium executeAsyncScript method.
String str = (String) js.executeAsyncScript("var myHeaders = new Headers();\n" +
"myHeaders.append('client-id', 'LPDP');\n" +
"myHeaders.append('a2z-csrf-token', 'NON_SDF');\n" +
"myHeaders.append('x-amz-rid', 'M6507NCWPW2FVPSSRMVM');\n" +
"\n" +
"let inputEntities = new Map();\n" +
"inputEntities.set(\"Commons$customerId\", \"\\\"A2ZLDCQRXMMNLG\\\"\")\n" +
"inputEntities.set(\"Commons$marketPlaceId\", \"\\\"A2XZLSVIQ0F4JT\\\"\")\n" +
"inputEntities.set(\"Commons$sessionId\", \"\\\"asdb3412\\\"\")\n" +
"inputEntities.set(\"Commons$ubId\", \"\\\"abc\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$eventId\", \"\\\"prsrohitest-1\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$clientId\", \"\\\"HFC\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$useCaseName\", \"\\\"lineItemPromotionPaymentMethodEvent\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$eventTimeStamp\",\"\\\"2022-04-20T21:21:57.934Z\\\"\" )\n" +
"inputEntities.set(\"Rewards$APPA$Commons$category\", \"\\\"HFC\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$subCategory\", \"\\\"PREPAID_RECHARGE\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$requestType\", \"\\\"HFCBP\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$partition\", \"\\\"useCaseName,category,subCategory\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$benefitsToBeEvaluated\", \"[\\\"GCCashback\\\",\\\"Coupon\\\",\\\"Membership\\\",\\\"ScratchCard\\\"]\")\n" +
"\n" +
"let entitiesToBeResolved = [\"Rewards$APPA$GetAllPromotions$applicablePromotionDetailList\"]\n" +
"\n" +
"const executeInput = {\n" +
"\"inputEntities\": Object.fromEntries(inputEntities),\n" +
"\"entitiesToBeResolved\": entitiesToBeResolved,\n" +
"};\n" +
"\n" +
"var obj \n" +
"\n" +
"fetch("url", {\n" +
" method: 'POST',\n" +
" headers: myHeaders,\n" +
" body: JSON.stringify(executeInput),\n" +
"})\n" +
" .then(response => response.text())\n" +
" .then(result => obj = result)\n" +
" .then(()=> console.log(obj))\n" +
" .catch(error => console.log('error', error));\n" +
"\n" +
" return obj;");
I am getting null in str variable. Thanks in advance for any help
Note: I'm not in the habit of using java so I don't know how to escape strings properly.
The general way to do this is:
js.executeAsyncScript("arguments[0]('foo')")
You can put that inside a promise's then and it will still work.
Related
I have this meeting appointment i'm trying to send from an .ics file.
This is the data
"BEGIN:VCALENDAR\n" +
"CALSCALE:GREGORIAN\n" +
"METHOD:PUBLISH\n" +
"PRODID:-//Send project Invite//EN\n" +
"VERSION:2.0\n" +
"BEGIN:VEVENT\n" +
"UID:gestionprojetsCalendarInvite\n" +
"DTSTART;VALUE=DATE-TIME:" +
convertDate(startDate) +
"\n" +
"DTEND;VALUE=DATE-TIME:" +
convertDate(endDate) +
"\n" +
"SUMMARY:" +
subject +
"\n" +
"DESCRIPTION:" +
description +
"\n" +
"LOCATION:" +
location +
"\n" +
to.filter(o => o != '').map(o => "ATTENDEE;MAILTO:" + o.email).join("\n") +
"\n" +
"BEGIN:VALARM" +
"\n" +
"TRIGGER:-PT15M" +
"\n" +
"ACTION:DISPLAY" +
"\n" +
"DESCRIPTION:Reminder" +
"\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR";
I want to know why, when I open the .ics file, it's saying "send update" instead of "send".
What I get :
What I want :
I believe it’s because you have static UID for all .ics you generated. "UID:gestionprojetsCalendarInvite\n"
UID aka unique ID, is supposed to uniquely represent a calendar event. When you open an ics file containing duplicated UID, your app (Outlook I guess?) thinks you want to update an existing event, not creating a new one.
Try give it a different UID to see if that solves your problem.
Ref: https://icalendar.org/New-Properties-for-iCalendar-RFC-7986/5-3-uid-property.html
I have a nested array inside a list like the following:
{total_results, page, results [id, species_guess, observed_on_details {date, week, month, hour, year}]}
I am trying to get just the id, species_guess, and date using forEach.
function observationSummary2(data) {
data.results.forEach(element =>
console.log('#' + data.results.id +
" - " + data.results.species_guess +
' (' + data.results.observed_on_details.date + ')')
);
}
This is saying " Cannot read property 'date' of undefined ". I have tried using a for loop like this and it worked just fine.
for (let i = 0; i < data.results.length; i++) {
console.log('#' + data.results[i].id + " - " + data.results[i].species_guess + ' (' + data.results[i].observed_on_details.date + ')');
}
Can anyone tell me where am I doing wrong here, sorry I am still new at this language.
you should use foreach as follow
function observationSummary2(data) {
data.results.forEach(element =>
console.log('#' + element.id +
" - " + element.species_guess +
' (' + element.observed_on_details.date + ')')
);
}
Instead of
function observationSummary2(data) {
data.results.forEach(element =>
console.log('#' + data.results.id +
" - " + data.results.species_guess +
' (' + data.results.observed_on_details.date + ')')
);
}
Replace "data.results" with "element"
function observationSummary2(data) {
data.results.forEach(element =>
console.log('#' + element.id +
" - " + element.species_guess +
' (' + element.observed_on_details.date + ')')
);
}
More info about "forEach()" here:
https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
In my form I have a total field which is the sum of several checkboxes. When it reaches 21 total page one must be created. below the code, which worked well in another case and this time it gives me a syntax error. someone there you an idea ??
Thank you in advance
this.getField("TOTAL").value =
this.getField("P6eval_competences.manageriales.0").value +
this.getField("P6eval_competences.manageriales.1").value +
this.getField("P6eval_competences.manageriales.2").value +
this.getField("P6eval_competences.manageriales.3").value +
this.getField("P6eval_competences.manageriales.4").value +
this.getField("P6eval_competences.manageriales.5").value +
this.getField("P6eval_competences.manageriales.6").value +
this.getField("P6eval_competences.manageriales.7").value +
this.getField("P6eval_competences.manageriales.8").value +
this.getField("P6eval_competences.manageriales.9").value +
this.getField("P6eval_competences.manageriales.10").value +
this.getField("P6eval_competences.manageriales.11").value +
this.getField("P6eval_competences.manageriales.12").value +
this.getField("P6eval_competences.manageriales.13").value +
this.getField("P6eval_competences.manageriales.14").value +
this.getField("P6eval_competences.manageriales.15").value +
this.getField("P6eval_competences.manageriales.16").value +
this.getField("P6eval_competences.manageriales.17").value +
this.getField("P6eval_competences.manageriales.18").value +
this.getField("P6eval_competences.manageriales.19").value +
this.getField("P6eval_competences.manageriales.20").value +
this.getField("P6eval_competences.manageriales.21").value +
this.getField("P6eval_competences.manageriales.22").value +
this.getField("P6eval_competences.manageriales.23").value +
this.getField("P6eval_competences.manageriales.24").value +
this.getField("P6eval_competences.manageriales.25").value +
this.getField("P6eval_competences.manageriales.26").value +
this.getField("P6eval_competences.manageriales.27").value +
this.getField("P6eval_competences.manageriales.28").value +
this.getField("P6eval_competences.manageriales.29").value +
this.getField("P6eval_competences.manageriales.30").value +
this.getField("P6eval_competences.manageriales.31").value;
if (getField("TOTAL").value == "21") {
var expTplt = getTemplate("NIVEAU MATURE");
expTplt.spawn(numPages, true, false);
}
I think you should use parseInt() method cause the values which are returned are not Integer rather they are Strings.
While porting an android app to iOS we hit a barrier:
We have a UIwebView set up to run HighCharts (it works with their provided sample), but we can't figure out how to pass variables to Javascript in order to display real time changes.
The android-equivalent of what we're trying to do is:
webView.loadUrl("javascript:" + "point = " + "[Date.UTC("
+ mYear + "," + mMonth + "," + mDay + "," + hr
+ "," + min + "," + sec + "),"
+ value+ "];");
or another example:
webView.loadUrl("javascript:" + "var curve_name = " + "'Illuminance';" +
"var unit_of_meas = " + "'lx';" +
"var x_axis_title = " + "'Date';" +
"var y_axis_title = " + "'Illuminance (lx)';" +
"var plot_title = " + "'Illuminance data';" +
"var plot_subtitle = " + "'';")
UIWebView has a method called stringByEvaluatingJavaScriptFromString that you can use to run a script. I think that you can also use it to just pass and initialize any variable that you like.
Can anybody help to assign this xml as constant string in javascript. How to assign this xml as constant without any changes?
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">
" +
"<wp:Tile>
" +
"<wp:BackgroundImage>" + TextBoxBackgroundImage.Text + "</wp:BackgroundImage>" +
"<wp:Count>" + TextBoxCount.Text + "</wp:Count>" +
"<wp:Title>" + TextBoxTitle.Text + "</wp:Title>" +
"<wp:BackBackgroundImage>" + TextBoxBackBackgroundImage.Text + "</wp:BackBackgroundImage>" +
"<wp:BackTitle>" + TextBoxBackTitle.Text + "</wp:BackTitle>" +
"<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" +
"
</wp:Tile> " +
"
</wp:Notification>";
Thanks in advance
JavaScript doesn't have a constant modifier.
Closest you could do is define it with defineProperty() and set writable to false.
Also, your string...
"<wp:Tile>
" +
...won't work as the parser currently doesn't support multiline strings. You'll need to break it up with " + " or use the escape character as the last character.