Why does selenium return utag["data"]
works but utag
fails?
How to return/retrieve/export the whole utag object (via selenium in python)?
typeof(dataLayer)
"object"
typeof(utag)
"object"
typeof(utag.db_log)
"object"
// on page https://tealium.com/
var testFunc = function(){
return dataLayer;
};
testFunc ()
// works
var testFunc = function(){
return utag.data;
};
testFunc ()
// works
var testFunc = function(){
return utag;
};
testFunc ()
// works
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://tealium.com")
#jsObj = '''utag_err''' # fails
#jsObj = '''console.log( utag )''' # fails
jsObj = '''utag.data''' # works
jsObj = '''utag["data"]''' # works
#jsObj = '''utag''' # fails
searchTxt= f'''return {jsObj}'''
driver.execute_script( searchTxt )
Utag contains circular structures. They are not always supported in other languages' structures and certainly not supported in JSON.
There are ways to stringify a circular object. See this post: How can I print a circular structure in a JSON-like format?
But I would just rebuild the object from scratch. You're unlikely to need 90% of utag object in Selenium anyway. Just have one function in code that builds a global utag object for you in Selenium and when you need more, you can just add fields in there. You can also add some simple processing in there too, so it would act as a utag wrapper for you.