Currently I have a form with 10 fields that I need to do sendkeys > store the value and after assert this value when save the form. For each of these fields I need to create a function and store the value in a variable or is there a better way?
My actual code:
var email = driver.findElement(By.name('email'));
email.sendKeys('info#domain.com');
email.getAttribute("value").then(function(email_text) {
var email = email_text;
});
Cheers,
Rafael
If I understand correct, the process looks like you should fill some fields, remember their values and check values after the form has been submitted.
There is no one standard decision for tasks like this, it depends on developer.
So, we know which values we need and can store it for example in map
{
'email':'example#email.com',
'telephone':111222333
}
Key is name for finding element, value - for sendKey and checkValue methods.
You should write two methods, which will work with test data map and will fill inputs and check values in cycle by map keys.
Do you mean you want to do this as an array?
// you can represent each field as an object
var fields = [
{ elementName: 'email', expectedText: 'info#domain.com' },
{ elementName: 'password', expectedText: 'bla bla bla' }
];
// sendKeys to each field with the specified text
fields.forEach(function(field) {
browser.driver.findElement(by.name(field.elementName)).sendKeys(field.expectedText);
});
// to get all the field text (from promises) and store it as an array
browser.controlFlow().execute(function() {
var textArray = [];
fields.forEach(function(field) {
browser.driver.findElement(by.name(field.elementName)).getAttribute('value').then(function(actualText) {
textArray.push({elementName: field.elementName, actualText: actualText});
});
});
return textArray;
}).then(function(storedTextArray) {
// do something with the stored text array here
});
Related
I've many small tables under IndexedDB, each to create a select in my HTML page.
So let's say one is created with:
store_dest_fam.createIndex("tdestf_id", "tdestf_id", { unique: true });
store_dest_fam.createIndex("tdestf_nom", "tdestf_nom", { unique: false });
a second one is:
store_frota.createIndex("tfrota_id", "tfrota_id", { unique: true });
store_frota.createIndex("tfrota_nom", "tfrota_nom", { unique: false });
If I create a function for each, in order to read value using "cursor" I build a loop in which I have:
var tdestf_id = cursor.value.tdestf_id;
var tdestf_nom = cursor.value.tdestf_nom;
and so on. That's OK.
But as I've many small tables, I want to create a "global function", with parameters like:
make_select(name_of_table,name_for_value,name_for_text);
with for example:
name_of_table = "TAB_START"; // Name of the table to search in
name_for_value = "tdestf_id"; // Name of the field which value would be use as "value" in the select-option
name_for_text = "tdestf_text"; // Name of the field which value would be use as "text" in the select-option
I can open the connection to the table using
var tx_menu = db_handle.transaction(name_of_table, 'readonly');
var store_menu = tx_menu.objectStore(name_of_table);
which is logical as db_handle.transaction wait for the "string name" of the table, which is what i'm providing. But in the cursor loop this don't work (which seem to be logical as curso need a pointer to its structure while I'm providing a string)
var data_value = cursor.value.name_for_value;
var data_text = cursor.value.name_for_text;
So th question is: how can I get the cursor item value, giving the "string name" of the field?
Are you asking how to dynamically access cursor.value.somethinghere? If so, you can use bracket notation. Assuming your asked for a fields tsestf_id and tdestgf_text and passed them as valueField and textField:
var data_value = cursor.value[valueField];
var data_text = cursor.value[textField];
I'm retrieving an OSM Json from an overpass call, to obtain a list of features that I have to save on a database. Since the data are very different from one another (for example, some of them do have a a tag called "addr:city", and some of them not), I would like to check if a key exists, and only in that case save the corresponding value. I've found only this question but it's not my case, since I do not know a priori which keys one element will have and which not, and since I'm working with a great load of data, I really can't check the elements one by one and of course I can't write an IF for each case.
Is there a way to solve this? I was thinking something about "if key has null value, ignore it", while looping over the elements, but I don't know if something like that exists
EDIT:
This is my query:
https://overpass-api.de/api/interpreter?data=[out:json][timeout:25];(node[~%22^(tourism|historic)$%22~%22.%22](44.12419,%2012.21259,%2044.15727,%2012.27696);way[~%22^(tourism|historic)$%22~%22.%22](44.12419,%2012.21259,%2044.15727,%2012.27696););out%20center;
and this is the code I'm using to save the data on firebase:
results.elements.forEach(e=>{
var ref = firebase.database().ref('/point_of_interest/');
var key = firebase.database().ref().child('point_of_interest').push().key;
var updates = {};
var data = {
città : e.tags["addr:city"],
tipologia: e.tags["amenity"],
indirizzo: e.tags["addr:street"],
nome: e.tags["name"],
lat: e.lat,
lon: e.lon
}
updates['/point_of_interest/'+key] = data;
firebase.database().ref().update(updates);
})
"results" is the response in json format
You could use something like that:
var attrs = ["addr:city", "amenity", "addr:street", "name"];
var labels = ["città ", "tipologia", "indirizzo", "nome"]
var data = { };
attrs.forEach((a, i) => {
if (e.tags[a]) { data[labels[i]] = e.tags[a]; }
});
You could even make this more dynamic, if you can query the attribute names and labels from somewhere.
Here I created tag using web tutorials.
JSFIDDLE : http://jsfiddle.net/karimkhan/A5TJh/1/
Inside:
for (var i in tags){
tagString.push(tags[i].value);
}
if I alert(tags[i]) it alerts correctly.
But when I use tags before end of function that it alerts undefined.
My purpose is to store all tags in an array and push POST this array to PHP file. But the issue is I am not able to retrieve tags value in array. As it is already in tags array, I thought I could access it directly.
You need values like 1, 2, 3 or tags names like tag1, tag2, tag3?
Call someMethod with argument like tagString
instance.tagit({
tagSource: availableTags,
tagsChanged: function () {
//Get the tags
var tags = instance.tagit('tags');
var tagString = [];
//Pull out only value
for (var i in tags) {
tagString.push(tags[i].value);
}
someMethod(tagString);
//Put the tags into the input, joint by a ','
input.val(tagString.join(','));
function someMethod(tags) {
console.log(tags);
// call POST action
}
}
});
I think it's easier to just retrieve the values from the DOM, rather than try to store them in an array. If you store them in array as they are being created, then you have to keep an eye on changes, such as if the user deletes one of the tags.
So I would just retrieve the values when the user performs their submit action. The values are stored in a hidden unordered list and each has a class of .tagit-choice, so just iterate over the list and retrieve the text values:
DEMO
$('.tagit-choice').each(function () {
alert($(this).contents(':not(a)').text());
});
Naturally, you can use the each method to create an array once you're ready to post like this:
tagsForPost = [];
$('.tagit-choice').each(function (i) {
tagObj = {value: i, label: $(this).contents(':not(a)').text()};
tagsForPost.push(tagObj);
});
console.log(tagsForPost);
I'm trying to generate markers for every user in my $.each loop in such a way that I can select each marker using the corresponding userId of a given user.
$.each($.parseJSON(window.usersArray), function (i, user) {
window.userMarkers[user['id']] = L.marker(98.76, 12.34).addTo(map);
console.log(window.userMarkers[user['id']]);
});
EDIT
I get the error:
Cannot set property '3' of undefined, where 3 is the user's ID.
You need to create the object (or array depending on your needs) before you can add anything to it.
window.userMarkers = {};
$.each($.parseJSON(window.usersArray), function (i, user) {
window.userMarkers[user['id']] = L.marker(98.76, 12.34).addTo(map);
console.log(window.userMarkers[user['id']]);
});
Solution: Define the array before setting properties to it! Example:
window.userMarkers = new Array();
I can take record from store: var record = store.getAt(i);
But if i want to take fileds which have a same name from record i get only first field value. For example if i have XML with:
Code:
<zem>
<parcel>
....
<parcel>
<really>
<price>555.555<price>
</really>
<really>
<price>666.666<price>
</really>
</zem>
And using record.get("price") i can get only 555.555 value.
Its possible to get values of all fields of <really>? Or array of values of all fields with name=<price>?
Take a walk on store:
var res = [];
store.each(function(record) { res.push(record.get('price')); })