how to check javascript variables in selenium script - javascript

I have a selenium script which creates a financial profile on a financial web application. Now i need to check whether added financial stuff appears in the profile.
For example i added a Retirement account to the profile and want to see if added retirement account appears in the profile. I have checked UI elements to verify that it appears in the profile. But i am wondering if there is a way to check same using javascript variables.
I found javascript executor function that can be used in Selenium but i am not sure how to check which variable or function to check for a particular account(Retirement).
I also read about some extensions that can show you java script variables called real time but have had no luck with using those efficiently.
Any help would be appreciated and an example small code would be very helpful. Thanks!

This seems like a duplicate question. But if executeScript doesn't return the variable to whichever language you are running Selenium in, then you can always dump the contents of the object to a DOM element and use Selenium to inspect it there.

Related

Code in Google Tag Manager does not working

I have a test tasks and 2 from 3 I've done.
But this one I don't understand how and what I need to do?!
I managed to find syntax error:
At first should be:
...function someFunctionName() {...}
or
(function() {...})()
...second it's anonymous function...
TASK:
This script is executed in GTM and implemented in Google analytics by custom Task.
The script sends information about user behavior to Optimozg server and then to Bigquery (bq.php file processes and forwards data). Optimozg server data is coming in correctly, but the data in Google Analytics does not reach.
What is the reason?
How do you fix it?
Hint:
(test the code on your site instance with GTM)
function(){return function(tracker){if("undefined"===typeof tracker.get("BigQueryStreaming")){var f=tracker.get("sendHitTask"),h=function(){function d(c){var a=!1;try{document.createElement("img").src=e(!0)+"?"+c,a=!0}catch(k){}
return a}
function e(c){var a="https://test.optimozg.com/bq/bq-test.php";c||(a+="?tid="+encodeURIComponent(tracker.get("trackingId")));return a}
return{send:function(c){var a;if(!(a=2036>=c.length&&d(c))){a=!1;try{a=navigator.sendBeacon&&navigator.sendBeacon(e(),c)}catch(g){}}
if(!a){a=!1;var b;try{window.XMLHttpRequest&&"withCredentials" in(b=new XMLHttpRequest)&&(b.open("POST",e(),!0),b.setRequestHeader("Content-Type","text/plain"),b.send(c),a=!0)}catch(g){}}
return a||d(c)}}}();tracker.set("sendHitTask",function(d){h.send(d.get("hitPayload"));tracker.set("BigQueryStreaming",!0)})}}}
Not sure why JS devs should know anything about GTM. They typically don't go there.
But yes, to understand how to use the given code properly, just read this article: https://www.simoahava.com/analytics/customtask-the-guide/ it describes what custom tasks are and how to use them.
Ok, so first make a GTM account. Deploy the GTM code on your site. May as well use a local site. Or, rather, have the GTM code being injected by a local extension to a random site that doesn't have GTM yet. Or maybe use a redirector extension to redirect the request for their GTM to yours, up to you.
After that, you just make a tag in GTM that would send a Universal Analytics pageview. GA4 decided not to bother with custom tasks, unfortunately, so UA only. Then you make a trigger on pageview. You assign the trigger to the tag. Don't forget to publish the workspace at least once for it to be testable. Then you preview. Preview is a CTA in GTM in top right corner, near the publish. Basically a neat GTM debugger. Enter the site where you have your GTM snippet deployed/injected. Make sure preview sees your tag firing on page load. That would mean you did the preparation correctly.
We're doing the Hint section here, by the way. Now you need to make a custom javascript variable in GTM, paste the code snippet as is in there. The reason why it wants the code in an anonymous function is because it will run it as a closure on it's own. So they kinda remove the need of the extra ()(). It's mostly done for people who don't know JS, so don't be surprised.
Ok, you've made the CJS var, now go to your tag, and set your customTag exactly as Simo shows in his article:
Good, now publish your container, go to the site where you have it deployed, open the network tab and reload the page.
Inspect the calls to the BQ and Optimozg endpoints. Now what they ask is, I believe, why the original call that is meant to be sent by the tag is not being send. So if you remove the setting of the customTask, then publish and reload the page, you should see a request to the collect endpoint, which is the GA's endpoint for data tracking. If you re-add the customTask code, it will prevent the normal tag's functionality from execution, so no collect call.
What they want to hear from you is how to make the tag fire the original event alongside their optimozg and bq calls.
Most likely, the answer is pretty simple and elegant, but requires a lot of debugging to reach to. Reading Simo's article will help understanding the significance of setting various tasks.
Uh, ok, I didn't mean to really debug it, but it looks like I found the bug. It's in the var f = tracker.get("sendHitTask") It's being used to store the original sendHitTask function, but it never gets used. Why is that? Basically, you just need to call the function in the new sendHitTask function that you set in the last line. I'm not going to debug it in my GTM, but I'm pretty sure that's the issue. It's kinda begging to be found there.
Also, this is not quite a junior JS dev task. It's a senior tracking implementation task. Basically, about $110/hr in Canada and US. Junior JS devs are around $35/hr, I guess. They're just trying to save money, heh. I was thinking of hiring junior JS devs instead of tracking implementators too, but it's hard to teach how data analysis works in all the different tools.

Trying to develop on Paypal Sandbox but Paypal isEligible js call always returns false when calling from Argentina, it works fine from US

I'm not finding anything about this in docs. This sandbox account works ok when the user is in USA but when I try to develop from Argentina i dont even see Paypal buttons cause isEligible() js function returns false. Is it related to my country? Being a dev environment is there any way to stop this validation for a while?
I log in the sandbox account and enter our E-Commerce site, paypal user is taken from my sandbox user that's already logged-in in the browser.
What I am doing is exactly what's explained here:
https://developer.paypal.com/docs/checkout/integration-features/standalone-buttons/
It works perfectly from United States but from Argentina IsEligible() always return false. I'm using the same Paypal Sandbox account.
It's unusual to be using standalone buttons, a simpler solution would be to just integrate Standard payments with smart buttons. There's also an interactive demo here where you can try everything out.
We can't comment on your specific attempt to use standalone buttons unless you update your question with a full HTML example of what is being done, including the line that loads the SDK script.
If your goal is to test what buyers from other countries will see, in sandbox mode you can add the query string parameter buyer-country=US or similar, as documented here. Do not use this parameter in live mode (with a live client-id) as it will not load.

Add a bookmark containing JavaScript, not a URL

I want to have a bookmark on my browser (Firefox 3 or Chrome preferably) that is only a snippet of JavaScript code. It would construct a URL based on the current date and then do a window.location =  on that URL.
I know that I could make a page and keep it on my local machine and just refer to it that way, but I was wondering if you could bypass that step and actually have the location of the bookmark really just be JavaScript. I could have sworn that this was possible years ago, but I can't find anything that tells me either way now.
You can do that by adding this to your favorites:
javascript:(function(){document.location.href="http://stackoverflow.com";})()
The correct name for this kind of bookmarks is favelets. For some more inspiration check out this collection of favelets.
Use as your bookmark’s address javascript:window.location='https://www.google.com/search?q='+Date();
to create a bookmarklet that searches Google for the current date and time.

How do I find out, using javascript, what software opened and running my application?

I have created an application in HTML5 and javascript that obviously will run in any browser, but it also can be loaded into another software (other.app) that uses its' functionalities.
I need to create a condition so when my app is loaded in a browser, it will not execute the functions that are referring to other.app.
Example:
function doStuff(){
if(isOtherApp){
doOtherAppFunction();
}
doAllOtherStuff();
}
Is there a way in javascript to find out what application loaded and is execution my application?
Hope this is clear enough. Thanks in advance for any suggestions.
There isn't a reliable way, but you can check a property provided by the JavaScript engine and test if it exists or has a certain value.
If your application is providing extra JavaScript methods and you only want to call them if they exist, then you can just test for their existence:
if (window.nonStandardFeature) {
window.nonStandardFeature();
}

Access Google-apps public spreadsheet via Javascript

Spent a bunch of time looking at this.. It seems that what little info there was about accessing a Google-apps spreadsheet is not very well maintained..
At Google IO this year there was an announcement of enhanced Google-apps script. Including UI elements..
That got me to thinking of creating a widget based on data in Google spreadsheets, no data writing just a simple reading/look up and display calculations.. Then I realized the UI feature was only available for Premier account.. Not a huge deal at only $50/yr and some free trial time up front. It seems that the ui feature may be somewhat restrictive.
But then I began to think about all the little things I might have to do,, so I started to investigate how to just access the spreadsheets from Javascript, in which case I think they could be a plain I-Google gadget.. an I-Google gadget is quite powerful and flexible in what it can do. And this could allow a lot more flexibility.. In short I've come up short.. anyone else out there? This sort of looked like a clue http://almaer.com/blog/gspreadsheet-javascript-helper-for-google-spreadsheets and this one which I could not fetch a current spreadsheet http://code.google.com/apis/gdata/samples/spreadsheet_sample.html but has not been touch for a long time and I could not make it work on a current spreadsheet.
Here is a current "public" read only spreadsheet. http://spreadsheets1.google.com/ccc?key=tzbvU7NnAnWkabYmGo4VeXQ&hl=en
This is in what Google now refers t as it's old format, I've tried both (old and new).. don't know if that makes any difference..
Google provide a documented way to access google spreadsheet via JSONP that works for normal gmail.com accounts. In short:
Create a spreadsheet
Click on the dropdown next to "Share" and select "Publish as a web page"
Copy and paste out the key from the URL that shows (i.e. the bit after &key=)
Go to https://spreadsheets.google.com/feeds/cells/0AmHYWnFLY1F-dG1oTHQ5SS1uUzhvTnZTSHNzMjdDaVE/od6/public/values?alt=json-in-script&callback=myCallback replacing "0AmHYWnFLY1F-dG1oTHQ5SS1uUzhvTnZTSHNzMjdDaVE" with whatever key you cut out of the url
To access this from within JavaScript you'll have to insert a HTML script tag into your document:
<script src="https://spreadsheets.google.com/feeds/cells/0AmHYWnFLY1F-dG1oTHQ5SS1uUzhvTnZTSHNzMjdDaVE/od6/public/values?alt=json-in-script&callback=myCallback"></script>
And you'll need to implement the callback function in your webpage:
function myCallback(spreadsheetdata) {
// do something with spreadsheet data here
console.log(spreadsheetdata);
}
You can simplify this with jQuery:
var url = "https://spreadsheets.google.com/feeds/cells/0AmHYWnFLY1F-dG1oTHQ5SS1uUzhvTnZTSHNzMjdDaVE/od6/public/values?alt=json-in-script&callback=?";
$.getJSON(url,{}, function (d) { console.log(d); });
I have implemented a fairly complete example and the code is at
https://bitbucket.org/tbrander/ggadget/wiki/Home
Code is BSD license (except for Trademarks and institutional markings which are all rights reserved)
It is reasonably well commented...
It is in operation at
http://acre.cba.ua.edu/ (bottom of page)
Stand alone at :
http://acre.cba.ua.edu/mobiletool/res.html
It functions across IE, Chrome FF i-Phone and Android
Your hints above are close but I was looking for yet more... as You can now see,, But I will explore the Jquery syntax as the current implementation is pure JS

Categories