Menjalankan javascipt di ui vision dengan executeScript dan ExecuteScriptSandbox – Untuk menjalankan javascript di uivision kita bisa menggunakan executeScript atau kita bisa menggunakan executeScript_Sandbox
Penggunaan executeScript_Sandbox
Javascript (executeScript_Sandbox recommended) | Result |
---|---|
return Math.floor(Math.random()*11) | Random number between 0 and 10 |
return Number (${i}) + 1; | Increase the value of i by one (very useful inside loops) |
var x=”abc”; return x.length; | Returns the length of the string (here 3). |
x=”${myvar}”; return x.length; | Same as above but with variable as input. |
var audio = new Audio(‘http://www.storiesinflight.com/html5/audio/shimmer.wav’);audio.play(); | Play sound! |
var d=new Date(); return d.getDate()+’-‘+((d.getMonth()+1))+’-‘+d.getFullYear(); | Get todays date |
var d= new Date(); var m=((d.getMonth()+1)<10)?’0’+(d.getMonth()+1):(d.getMonth()+1); return d.getFullYear()+”-“+m+”-“+d.getDate(); | Get todays date in YYYY-MM-DD format |
var d= new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * 5); var m=((d.getMonth()+1)<10)?’0’+(d.getMonth()+1):(d.getMonth()+1); m=d.getFullYear()+”-“+m+”-“+d.getDate(); return m | Get yesterday’s date (-1), tomorrows date (1) or the date in 5 days (5) => Just change the number 5 in the code snippet. |
return parseFloat(“${!runtime}”)-parseFloat(“${starttime}”); |
Calculate the difference between the current runtime and the start time. Very useful for measuring website performance |
var x = parseInt((new Date(‘2018-03-20T12:00:00’) – new Date()) / 1000); return Math.max(0, x); |
Countdown to specific date and time. Use the result as input for PAUSE |
return [“Hello”,”Bonjour”,”你好”]; |
Create a Javascript array. You can use for Each to loop over the array. |
Penggunaan ExecuteScript
Javascript (executeScript only) | Result |
---|---|
return window.document.getSelection().toString() |
Copy selected text (e. g. text marked with Ctrl+A) |
alert(“Hello World!”) |
Show an alert box. [Needs website] Note: Since Chrome 64 the prompt box is only shown (by Chrome) if the tab has the focus. This is a change in Chrome, not Kantu. Better use PAUSE | 0 |
return prompt(“Please enter a value”) |
Ask user for input and store it in a variable. Note: Since Chrome 64 the prompt box is only shown (by Chrome) if the tab has the focus. This is a change in Chrome, not Kantu. Better use the internal PROMPT command of Kantu. |
return window.document.getElementsByName(‘Phone’)[0].value; |
Retrieve the field value an input box. This is also a replacement for storeValue from the old IDE. storeAttribute does not work with input boxes. |
return document.getElementByClassName(“label-bold”)[0].innerHTML; |
Extract some data, in this case from “<div class=“label-bold”> Order Number# 123456 </div>” |
window.history.go(-1); |
Simulate BACK button click |