first of, I'm a total, utter newbie. I have to work with this, because nobody in my office is even halfway computer literate. The person who wrote the initial script left the company and we can't get ahold of him anymore.
Now, the problem at hand:
I have a script that's a "look for words and highlight them in garish colour" affair. Now I tried to modify it so that it only runs in a
This is the code:
function Find(node){
if(!node)
node=document.getElementsByTagName('div class="listing__top-info"')[0];
this.rootNode=node;
this.hits=0;
this.selected=0;
this.selection=[];
this.build();
Yet when I run this code, I get this in the log:
"TypeError: document.getElementsByClassName(...)[1] is undefined" (I also don't understand why the [0] gets changed to a [1] here.)
The script is already set to run at document-idle.
The version of the script that works, is set to look for "body", and then marks/highlights as intended.
What am I missing?
Try using querySelector instead:
node = document.querySelector('div.listing__top-info');
Related
There are several questions with this error but I seem to get this error while the element is certainly there.
This is the test code:
it.only('changes product attributes and sku', () => {
cy.visit('/product/hoganrebel-r261-sneaker-6708K62AZC-grey/M0E20000000DX1Y');
cy.get('[data-test=product-data]')
.then(($product) => {
cy.wrap($product)
.find('[data-test=attribute-select-Size]')
.select('6');
cy.url().should('include', 'M0E20000000DX20');
cy.wrap($product)
.pause()//here I can see the element but when I step into find it fails
.find('[data-test=attribute-select-Size]')
.select('7');
cy.url().should('include', 'M0E20000000DX22');
});
});
I install dependencies with npm ci and run the project with yarn start.
In another terminal tab I start the test with ./node_modules/cypress/bin/cypress open and then choose "run all specs" (only runs the it.only test). When it pauses I can clearly see the element but when opening the devtools and run document.querySelector('[data-test="attribute-select-Size"]') in the console it says null. Then I right click on the clearly visible element and choose inspect it shows me the element. Then go back to the console and run document.querySelector('[data-test="attribute-select-Size"]') again it gives me the element.
Adding a .wait(5000) before the pause does not solve this, could try to wait for xhr to finish but it has already finished after 5 seconds so that is not likely to be the problem.
This is obviously a bug but I'm not sure how to work around this issue.
Detached elements are usually due to the framework re-writing sections of DOM with the same data selector ([data-test=product-data]) that it had before, but creating a new instance of the element.
When you hold on to a reference with test code like .then(($product) => { cy.wrap($product)..., $product is no longer valid after the re-write (I guess caused by .select('6') but I didn't dig into your app code to verify).
The short answer is repeat the cy.get('[data-test=product-data]') selection, there is no reason to grab a specific reference to that element.
it('changes product attributes and sku', () => {
cy.visit('/product/hoganrebel-r261-sneaker-6708K62AZC-grey/M0E20000000DX1Y');
cy.get('[data-test=product-data]')
.find('[data-test=attribute-select-Size]')
.select('6'); // DOM changes here?
cy.url().should('include', 'M0E20000000DX20');
cy.get('[data-test=product-data]') // fresh DOM query
.find('[data-test=attribute-select-Size]')
.select('7');
cy.url().should('include', 'M0E20000000DX22');
});
I have a classic asp project. In one of my pages i have to call a javascript function. That call does not have any problem and works fine on my test server (not localhost, just a server to test he project). But when i deploy it to the actual server, that function does not work. I call this function in onload event.
That function has this type of lines (i cannot write the whole code, because of the company that i work for, does not allow it)
document.getElementById("R6C2_1").style.display = 'block'
document.getElementById("R6C2_2").style.display = 'none'
....
When I try to debug it on IE10, i got "Unable to get property 'style' of undefined or null reference" error. After that, the elements in javascript function are not load. They are not seen on the page.
My main problem is, as i mentioned before differences between servers. I do not understand why it works on one server, but not on another server.
While it's not possible to determine the issue from this information alone, you should look into:
Whether the elements you're looking for actually exist when the code is invoked (use browser debug / breakpoints to look at the page the moment the code is invoked).
If they exist, check if they have the ID you expect (e.g R6C2_1) - if not, why? who creates these IDs? could be a server configuration issue.
Do a debug using the app from each server, and look at the page / DOM, see if there are differences or check if the code is invoked at different times.
These could lead you to pinpoint the issue. Good luck!
In case the elements just take time to be created, you can just wait until they are present:
function ExecuteWhenExists() {
var R6C2_1 = document.getElementById("R6C2_1");
var R6C2_2 = document.getElementById("R6C2_2");
if (R6C2_1 && R6C2_2) {
R6C2_1.style.display = 'block';
R6C2_2.style.display = 'none';
} else {
window.setTimeout(ExecuteWhenExists, 100);
}
}
ExecuteWhenExists();
This will not crash when the elements do not exist, and will just keep trying to execute in a non-blocking way (polling every 0.1 seconds) until they exist.
I am having some issues with a class project. Every thing was working fine and dandy up until the current part we are on. Basically, we had to add prototypes and cases to move to each location. Now my code will not work, and the teacher is about as helpful as a pet rock. I have two parts to my code, the html (which has part of the code including items and such) and the .js file that includes the locations.
I have created a repository on Github so it is easily accessible to all who want to help. At this point it is too late to submit to my professor, but I am curious on what I did wrong.
https://github.com/EmeraldX/Project-Help/tree/master
The main and directions.js are the files that I am currently working with.
Thanks!
Update: Okay, so it's still not working, and when I use Chrome's console it just tells me that:
function updateDisplay( message ) {
var textArea = document.getElementById("introduction");
textArea.value = message + "\n\n" + textArea.value;
Cannot read property 'value' of null
I tried opening your html page and js using firefox, and used the firebug consol to see if anything was wrong.
It looks like you have an ) missing in your js:
SyntaxError: missing ) after argument list directions.js:7:145
And it was right:
locations[2] = new Location(2,"Lake","A large lake that is formed by a river flowing from the East.",
new Item(1,"Fish","An old rotting fish.");
is missing a ')'
After correcting it, it appear that you miss this ) line 7, 9, 13 and 14.
Then a new error pop up:
ReferenceError: Item is not defined directions.js:7:2
This can be corrected by calling your direction.js AFTER you js script in main.html.
Hope it can help
Making a site that has a videos that are inside Iframe opened with Highslide. It all works great except in IE. When I close the Highslide (and delete the Iframe inside), I get these error messages :
SCRIPT5007: Unable to get property 'random' of undefined or null reference
File: jquery.min.js, Line: 2, Column: 1711
SCRIPT5009: 'jQuery' is undefined
File: flowplayer.min.js, Line: 6, Column: 1
SCRIPT5009: 'flowplayer' is undefined
File: index.php, Line: 20, Column: 4
Occasionally I get a repeating error of:
SCRIPT445: Object doesn't support this action
File: jquery.min.js, Line: 2, Column: 4058
If I reopen the exact same Highslide Iframe right after the error occurs, it'll open just fine without any problems, but still have errors on close. I'm honestly stumped on what to do to fix this.
It sounds like what you've encountered is a weird corner bug with IE. Basically, if an iframe is in another element, in certain cases, when that element is destroyed, the scripts in the iframe will run again, this time with no context - things like Object and Math will just be gone.
Because these are scripts running on a destroyed iframe, I've found the errors to generally be harmless, but I still don't like having them.
I found that something about the interaction between IE and jQuery (1.11.0) seems to cause this. Try emptying out the element containing the iframe using pure DOM calls first:
// Instead of:
//$('div').empty();
// Run this:
var div = $('div')[0];
while (div.firstChild) {
div.removeChild(div.firstChild);
}
No idea why this works, or even if it works in most cases (it worked in my sandbox but not in actual code), and no interest in further diagnosing IE's weird maladies, but it does seem to sometimes eliminate the error and essentially work the same way. :)
In the highslide-full.js file (version 4.1.12), in the afterClose function (somewhere around line 2926) you should find this:
if (this.outline && this.outlineWhileAnimating) this.outline.destroy();
Immediately after that line, add this:
if (this.iframe) {
this.body.removeChild(this.iframe);
}
We've solved our IE9 closing issue with that extra code.
I realise this is not the ideal place to ask about this in terms of searchability, but I've got a page whose JavaScript code throws "Stack overflow in line 0" errors when I look at it in Internet Explorer.
The problem is quite clearly not in line 0, but somewhere in the list of stuff that I'm writing to the document. Everything works fine in Firefox, so I don't have the delights of Firebug and friends to assist in troubleshooting.
Are there any standard causes for this? I'm guessing this is probably an Internet Explorer 7 bug or something quite obscure, and my Google-fu is bringing me little joy currently. I can find lots of people who have run into this before, but I can't seem to find how they solved it.
I ran into this problem recently and wrote up a post about the particular case in our code that was causing this problem.
http://cappuccino.org/discuss/2010/03/01/internet-explorer-global-variables-and-stack-overflows/
The quick summary is: recursion that passes through the host global object is limited to a stack depth of 13. In other words, if the reference your function call is using (not necessarily the function itself) was defined with some form window.foo = function, then recursing through foo is limited to a depth of 13.
Aha!
I had an OnError() event in some code that was setting the image source to a default image path if it wasn't found. Of course, if the default image path wasn't found it would trigger the error handler...
For people who have a similar problem but not the same, I guess the cause of this is most likely to be either an unterminated loop, an event handler that triggers itself or something similar that throws the JavaScript engine into a spin.
You can turn off the "Disable Script Debugging" option inside of Internet Explorer and start debugging with Visual Studio if you happen to have that around.
I've found that it is one of few ways to diagnose some of those IE specific issues.
I had this problem, and I solved it. There was an attribute in the <%# Page tag named MaintainScrollPositionOnPostback and after removing it, the error disapeared.
I added it before to prevent scrolling after each postback.
If you came here because you had the problem inside your selenium tests:
IE doesn't like By.id("xyz"). Use By.name, xpath, or whatever instead.
Also having smartNavigation="true" causes this"
I set up a default project and found out the following:
The problem is the combination of smartNavigation and maintainScrollPositionOnPostBack. The error only occurs when both are set to true.
In my case, the error was produced by:
<pages smartNavigation="true" maintainScrollPositionOnPostBack="true" />
Any other combination works fine.
Can anybody confirm this?
Internet Options
Tools
Internet options
Advanced
Navigation section
Click > Disable script debugging
display a notification about every script error
sign in
You will smile !
My was "at line 1" instead but...
I got this problem when using jQuery's .clone method. I replaced these by using making jQuery objects from the html string: $($(selector).html()).
I have reproduced the same error on IE8. One of the text boxes has some event handlers to replace not valid data.
$('.numbersonly').on("keyup input propertychange", function () {
//code
});
The error message was shown on entering data to this text box. We removed event "propertychange" from the code above and now it works correctly.
P.S. maybe it will help somebody
I don't know what to tell you, but the same problem occured with jQuery table sorting and SEARCH.
When there is nothing left in the table, where you are searching a string for example, you get this error too. Even in Google Analytics this error occurs often.
In my case I had two functions a() and b(). First was calling second and second was calling first one:
var i = 0;
function a() { b(); }
function b() {
i++;
if (i < 30) {
a();
}
}
a();
I resolved this using setTimeout:
var i = 0;
function a() { b(); }
function b() {
i++;
if (i < 30) {
setTimeout( function() {
a();
}, 0);
}
}
a();
This is problem with Java and Flash Player. Install the latest Java and Flash Player, and the problem will be resolved. If not, then install Mozilla Firefox, it will auto install the updates required.