The X and Y value changes when I move the cursor.
I am able to get the X axis value as there is an element in the script.
driver.find_element(By.CLASS_NAME, "stx-float-date.floatDate").text
But the Y values is updated through JavaScript and I am not able to return the value. There are 2 functions used to get and display the value but I am not able to read the value.
Function to calculate the value
driver.execute_script("""return z7L""")
driver.execute_script("""return window.z7L""")
driver.execute_script("return transformedPriceFromPixel()")
Function to display the value
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[#class='stx-float-price']"))).get_attribute("innerHTML")
driver.execute_script("return q$v.ChartEngine.prototype.updateFloatHRLabel()")
I have even tried using Local storage but the variables are not stored there
driver.execute_script("return window.localStorage;")
Related
I have an application written in python plotly dash. In this application I have a hidden input element specified below.
dcc.Input(id='output-gcps-to-map', type='hidden')
I also have a javascript function that updates the value of this element from a global variable drawnPoints.
function saveGcps(){
let gcps = document.getElementById('output-gcps-to-map');
let gcpsToSave = [];
for (gcp of drawnPoints){
gcpsToSave.push([gcp[2],gcp[3]]);
}
gcps.value = JSON.stringify(gcpsToSave);
}
The element 'output-gcps-to-map' is correctly updated by this function and adds an additional point to the collection.
Then I click my button linked to the plotly dash callback below.
#app.callback(
Output("georef-image", "value"),
[Input("georef-image", "n_clicks"), Input("output-gcps-to-map", "value")]
)
def georeference_image(n1, gcps):
#does image exist
#do 3 gcps exist
if n1:
return True
return False
At this point the callback is just a dummy function returning a hardcoded boolean, but the parameter "gcps" should contain the value in the hidden input element 'output-gcps-to-map'.
However, when I examine the parameter for a value it is 'None'.
Why does my callback not contain the value updated by my JavaScript function?
How can I fix this so that the updated value is persisted through to my dash application?
I want an easy way to set a variable value equal to n when function(n) runs.
Hovedkort
Prosessor
Arbeidsminne
I have this piece of HTML code. And I want the loadProdType function to change the value of a variable prodCat according to loadProdType's value. I tried the code under with and witout localstorage.setItem(loadCat, j). The js document is linked and there are no linking errors cause other pieces of code runs as it should.
var loadCat = 0
function loadProdType(j){
loadCat = j}
How can I set loadCat's value equal to loadProdType's value/parameter.
Thanks in Advance.
Edit:
Unsure how to set local storage for this but what I want the code to do is the following:
Change the value of variable prodCat according to the value of the onclick function.
Redirect to: products.html
When in products.html I run a piece of code that uses the prodCat value to choose a spesific index in an array.
All in all I just need to be able to change prodCat on one page(to the value of a funcion or with a onclick) and have it saved on the next.
Last edit
I'll create different functions for each onclick and try that with local storage.
You need either ? in the URL or local storage.
?
In main document:
location.href = "products.html?prodType=" + loadCat;
In products.html:
var loadCat = new URL(document.URL).searchParams.get("prodType");
localstorage
In main document:
window.localStorage.setItem("prodType", loadCat);
In products.html:
var loadCat = window.localStorage.getItem("prodType");
How do I get variable value in __javaScript function ?
My code:
String[] zoollevelParams = Parameters.split(",");
Random random = new Random();
int zoomValue= Integer.parseInt(zoollevelParams[random.nextInt(10)]);
double lat = 50.669;
double lng = 5.499;
int numTiles = ${__javaScript(Math.pow(2\, "${zoomValue}"))};
This code is unbale to get value of zoomValue in __javaScript function call, how do I get value in this function?
You can't combine Java and Javascript code and don't need to.
Just keep using Java and take parameter from JMeter variables object vars:
int numTiles = Math.pow(2, vars.get( "zoomValue"));
Note: If you save zoomValue as Double or not a regular String use vars.getObject
Don't inline JMeter Variables or Functions into scripts, particular in your case __javaScript function is being executed before zoomValue is getting initialized.
Make sure you use the relevant JSR223 Test Element
Make sure you select groovy from the "Language" dropdown
Make sure you have Cache compiled script if available box ticked
Amend the last line of your code to look like:
int numTiles = Math.pow(2, zoomValue)
Demo:
Check out Apache Groovy - Why and How You Should Use It article for more details on using Groovy for scripting in JMeter tests.
I recently created an input box in HTML:
<input type="number" id="aa" onchange="yy()">
<p id="xx"></p>
Then I called the following code:
var gg = document.getElementById("aa").value;
function yy(){
document.getElementById("xx").innerHTML = gg;
}
Nothing appeared.
However if I change the script into:
function yy(){
gg = document.getElementById("aa").value;
document.getElementById("xx").innerHTML = gg;
}
It worked!
I thought that if I declared the variable gg first (global), I could use the value in the yy function. Why does the first code not behave like the second code?
Thats because you didn't put the value inside the function. Now var gg will always hold the initial value. Which is on page load empty.
By putting it inside the function. The value will be retrieved as soon as the function gets triggered. In your case, you putted a onchange trigger on it.
So when the value changes, the function will run at that moment, and retrieves the value inside the input field.
You can only get something if you ask for it. Or in this case JavaScript can only get something if something asks for it
Your function in the first case doens't ask for a value. In your seconds case, JavaScript asks the value of element #aa
You can still use gg inside yy function. But the thing here is the value you have inside gg. Since you are calling
var gg = document.getElementById("aa").value;
on page load, the input element do not have any value so the value of gg is always blank. And now when you change the value for id="aa" you are using the value of gg for its innerHTML and you always get blank. Now, the only fix is that, since your innerHTML depends on value of gg (Which is for input with id aa), you must include this inside your change() function to get correct output. Thus, the reason is not that you cannot access or get the value of global variable- you can but in this case the value is incorrect as expected.
For proper verification and understanding here is an example that has the value of id='aa' already specified then when you change the input then you get to see the value of gg:
var gg = document.getElementById("aa").value;
function yy(){
document.getElementById("xx").innerHTML=(gg);
}
<input type="number" id="aa" onchange="yy()" value='123'>
<p id="xx"></p>
I need to update length variable that was defined in imacros js in macro.js. I have tried different code but not able to pass information from imacros(js on page) to imacro.js (js of imacro);
for example;
var lenght = 0;
iimPlay("CODE:URL GOTO=JAVASCRIPT:var<SP>len=window.document.getElementById('table1').getElementsByTag('tr');");
now how to pass that inner len variable info to outer length variable. i need to run a loop based on length.
I can pass info from JS part to Imacros part with iimSet('var',var); is there any way I can update JS variable's value inside imacros code.;
Here is a trick with an ‘alert’ dialog:
var length = 0;
iimPlay("CODE:URL GOTO=JAVASCRIPT:alert(window.document.getElementById('table1').getElementsByTag('tr').length);");
length = parseInt(iimGetErrorText().match(/Dialog message: "(.*)",/)[1]);