Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error : unable to locate menu element #14

Open
Glecun opened this issue Jun 29, 2017 · 3 comments
Open

Error : unable to locate menu element #14

Glecun opened this issue Jun 29, 2017 · 3 comments

Comments

@Glecun
Copy link

Glecun commented Jun 29, 2017

Hi,

I've got the message: "unable to locate menu element" in the console when I load the page with the script enabled.

I think the error is here:
var menu = ui.search('//div[@class="nav-section-divider"]')[0];
He can't find it anymore for some reason... Maybe the HTML has been updated :/

So I replaced it with
var menu = ui.search('//div[@id="music-content"]')[0];

Just for you know ;)

@soulfx
Copy link
Owner

soulfx commented Jun 30, 2017

thanks for the feedback.

seems like it still works for me on the old DOM path. i think google uses different UIs for different regions, so maybe that could be it.

there used to be ways I can trigger that error if I do things like interrupting the loading of the page before it's completely loaded in the dom for the menu. i can't seem to reproduce it right now though.

@Glecun
Copy link
Author

Glecun commented Jun 30, 2017

Actually, I think we 've got the same DOM :)

I checked with jquery when the page was loaded and the <<//div[@Class="nav-section-divider">> is here:
image

I'm pretty sure that, with me, the page isn't fully loaded when the addui function is called. Because I tried to set a timeout and it worked perfectly this time :/

This code doesn't work:

var addui = function() {
    var ui = new XDoc(document);
    //var menu = ui.search('//div[@id="music-content"]')[0];
    var menu = ui.search('div[@class="nav-section-divider"]')[0];
    var inputui = ui.create('input',false,{'type':'file'});
    var importui = ui.create(
        'div',[ui.create('h4','Import Playlists'),inputui]);
    var exportlink = ui.create('a','Export Playlists',{'href':'#exportCSV'});
    var exportui = ui.create('div',ui.create('h4',exportlink));
    var statusout = ui.create('h6','ready');
    var statusui = ui.create('div',[statusout]);
    stat.element = statusout;
    var exporter = new Exporter();
    exporter.listenTo(exportlink);
    var importer = new Importer();
    importer.listenTo(inputui);
    if (menu) {
        menu.appendChild(importui);
        menu.appendChild(exportui);
        menu.appendChild(statusui);
    } else {
        console.log('unable to locate menu element');
    }
};
window.addEventListener ("load", addui, false);

But that dirty code works ;) :

var addui = function() {
    setTimeout(function(){
        var ui = new XDoc(document);
        var menu = ui.search('//div[@class="nav-section-divider"]')[0];
        var inputui = ui.create('input',false,{'type':'file'});
        var importui = ui.create(
            'div',[ui.create('h4','Import Playlists'),inputui]);
        var exportlink = ui.create('a','Export Playlists',{'href':'#exportCSV'});
        var exportui = ui.create('div',ui.create('h4',exportlink));
        var statusout = ui.create('h6','ready');
        var statusui = ui.create('div',[statusout]);
        stat.element = statusout;
        var exporter = new Exporter();
        exporter.listenTo(exportlink);
        var importer = new Importer();
        importer.listenTo(inputui);
        if (menu) {
            menu.appendChild(importui);
            menu.appendChild(exportui);
            menu.appendChild(statusui);
        } else {
            console.log('unable to locate menu element');
        }
    }, 3000);
};
window.addEventListener ("load", addui, false);

Strange isn't it ?

@aav7fl
Copy link

aav7fl commented Nov 26, 2017

@Glecun Thanks for providing that fix! You really saved my day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants