the property of the "Stub Object" object does not meet the checkpoint's condition - javascript

"the property of the "Stub Object" object does not meet the checkpoint's condition" –I got this error, I tried every type of checkpoint.
for (i = 0; i < rows; i++) {
j = 1;
cellvalue = grid.wValue(i, j);
grid.ClickCell(i, j);
//The problem is this checkpoint;
aqObject.CheckProperty(Aliases.browser.page1921681611258080.panelTabpanelBody.p‌anelGamblerpanel.panelTabpanel.panelForm.panelFormtargetel.panelContainer2.tableD‌​ isplayfield4.panelDisplayfieldInputel, "contentText", cmpEqual, "995");
}

The error you get means that the object you pass to the CheckProperty method is not found. You can check the object for existence before calling the checkpoint.
for (i = 0; i < rows; i++) {
j = 1;
cellvalue = grid.wValue(i, j);
grid.ClickCell(i, j);
var obj = Aliases.browser.page1921681611258080.panelTabpanelBody.p‌anelGamblerpanel.panelTabpanel.panelForm.panelFormtargetel.panelContainer2.tableD‌​ isplayfield4.panelDisplayfieldInputel;
//The problem is this checkpoint;
if (false == obj.Exists)
Log.Error("The object is not found");
else
aqObject.CheckProperty(, "contentText", cmpEqual, "995");
}

Related

Javascript: Assign values to a multidimendional array

I'm new at Javascript. I'm trying to assign a string to a multidimensional array with a very basic code, which is the following one:
var tab = document.getElementById("optionsTable").innerHTML.replace(identifier, "doc" + value);
$('#optionsTable').html('' + tab);
var table = document.getElementById("optionsTable");
for (var i = 1; i < table.rows.length; i++) {
for (var j = 0; j < table.rows[i].cells.length; j++) {
if (i == 1 && j == 0) {
table.rows[i].cells[j] = 'apple';
alert(table.rows[i].cells[j].innerHTML);
}
}
}
I use variable tab because I need to change the html of the table.
When the alert message appears it shows that the value of the array was not changed to 'apple' as it should be. I'm not getting errors. What am I doing wrong?

why does it returns '-1' instead of the index of the index jQuery

I'm running a 'for' loop to check if the elements in the winOptions array are in the oneNums array. However, every time I use indexOf property it sends back -1 even if the number is in the oneNums array. Is it possible it returns that because ['1','2'] is different that [1,2]? How can I fix this.
I have this variables:
var oneNums = [];
var winOptions = [[1,2,3],[4,5,6],[7,8,9],[1,5,9],[3,5,9],[1,4,7],[2,5,8],[3,6,9]];
var a;
And this jQuery function:
$('.btn-xo').click(function(){
if (turn === 'one'){
$(this).text(pickOne);
$(this).prop('disabled', true);
oneNums.push($(this).val());
oneNums.sort(function(a, b){
return a - b;
});
for(var i = 0; i < winOptions.length; i++){
for(var j = 0; j < winOptions[i].length; j++){
a = oneNums.indexOf(winOptions[i][j]);
if (a === -1){
p1 = [];
break;
} else {
p1.push(oneNums[a]);
console.log('aca');
}
}
}
console.log(a);
turn = 'two';
count += 1;
}
indexOf string with number will fail. So, change number to string
First convert number to String, using .toString()
for(var i = 0; i < winOptions.length; i++){
for(var j = 0; j < winOptions[i].length; j++){
a = oneNums.indexOf((winOptions[i][j]).toString());
if (a === -1){
p1 = [];
break;
} else {
p1.push(oneNums[a]);
console.log('aca');
}
}
}
Check these two examples,
['1','2'].indexOf(1); o/p ===> -1
['1','2'].indexOf((1).toString()); o/p ===> 0

Remove attributes from html string - error with removeAttributeNode

I am trying to remove all attributes except for certain whitelisted ones from a long html string. I am using the DOM to parse it.
I know there are a lot of other questions about this, but my question is specifically about the error I am getting with executing removeAttributeNode in my code below.
var div = document.createElement('div');
div.innerHTML = '<p class=\"p\">text here</p> <div id=\"divId\"></div>';
var elements = div.getElementsByTagName('*');
var whitelist = ["src", "width", "height"];
for (var i = 0; i < elements.length; i++) {
if (elements[i].attributes.length !== 0) {
var attr = elements[i].attributes;
for (var j = 0; j < attr.length; j--) {
var attrName = attr[j].name;
for (var k = 0; k < whitelist.length; k++) {
if (attrName !== whitelist[k])
elements[i].removeAttributeNode(attr);
}
}
}
}
But, I keep getting the following error: Failed to execute 'removeAttributeNode ' on Element: the 1st argument provided is either null, or an invalid Attr object.
But, I checked with console statements and elements[i] is not null. For example, elements[0] = <p class="p">. How do I get removeAttributeNode to work? Thank you for your help!
In the last loop, do something like this.
for (var k = 0; k < whitelist.length; k++) {
if (attrName !== whitelist[k])
{
elements[i].removeAttributeNode(elements[i].getAttributeNode(attrName ));
}
}

checking multiple elements in javascript array

I have an array 'type' with multiple elements.how to check two elements contains in 'type' array?
i have tried the below code
var i, j;
var type = [];
for (i = 1; i <= count; i++)
{
var filetype_value = parseInt((document.submission['select_type_' + i].value));
type.push(filetype_value);
}
function search(arg)
{
for (j = 1; j <= count; j++)
{
if (type[j] === arg)
{
return true;
}
else
{
return false;
}
}
}
if(search(1) && search(2))
{
alert("Contains in array")
}
There is some problems with your approach.
1) You are just checking if type[1]===arg it will return true otherwise it will return false. So it will just check for type[1].
2) because file_type value is string so filetype_value' === arg is never going to be true.
3) In your loop j=1 will never check for first element of array.
Try this
function search(arg){
var matched = false;
for (j = 0; j <= type.length; j++){
if (type[j] == arg){
matched = true;
break;
}
}
return matched;
}
You have 2 problems
You are pushing the string "filetype_value" onto your array and not the actual value so in your search function you are actually testing: 'filetype_value' === arg
You are starting your loop using 1, array's start at an index of 0
change
type.push('filetype_value');
to
type.push(filetype_value);
change
for (j = 1; j <= count; j++)
to
for (j = 0; j <= count; j++)
Also instead of doing a loop you can use the array indexOf method to test if a value is in the array
function search(arg){
return type.indexOf(arg) !== -1;
}

undefined is returned in JavaScript function

When I call this function, sending for example: abc as the parameter,
the function returns: undefinedcba. I can't figure out why it's adding
'undefined' to my returned value. I'm probably overlooking something obvious
but I can't spot it. Thank you.
function FirstReverse(str) {
var str_arr1 = new Array();
var ans = '';
for(i=0; i < str.length; i++) {
str_arr1.push(str.charAt(i));
}
for(j=str.length; j >= 0; j--) {
ans += str_arr1[j];
}
return ans;
}
Strings are 0-indexed. str[str.length] does not exist.
j needs to start at str.length - 1.
Or, just return str_arr1.join();
The index of the string starts at 0, so string.length is always one number bigger than index of the last character in the string.
In the second for loop, use
for(var j=str.length -1; j >= 0; j--) {
The error is in the second for statement. See the solution:
function FirstReverse(str) {
var str_arr1 = new Array();
var ans = '';
for(i=0; i < str.length; i++) {
str_arr1.push(str.charAt(i));
}
for(j=str.length-1; j >= 0; j--) {
ans += str_arr1[j];
}
return ans;
}
Because when you pass 'abc' there are only 3 characters in it.
So arrray str_arr have elements at index 0, 1 and 2.
But you are looping for str.length i.e. for 3 times and str_arr[3] is not defined.
You should do this,
function FirstReverse(str) {
var str_arr1 = new Array();
var ans = '';
for(i=0; i < str.length; i++) {
str_arr1.push(str.charAt(i));
}
for(j=str.length-1; j >= 0; j--) {
ans += str_arr1[j];
}
return ans;
}
Looks like you want to reverse a string, which you can do in this javascript one liner
function reverse(s){
return s.split("").reverse().join("");
}
The reason you are getting an undefined is because your j starts with str.length, whereas it should be str.length-1. str_arr1[str.length] is out of bounds and therefore will be undefined.

Categories