等到元素可点击/可见js

问题描述

我正在编写Chrome扩展程序。所以问题是页面加载后我的代码没有启动。 Chrome告诉我我有一个错误,即元素为'null',但是元素存在:

element is 'null',but element is existing

我尝试使用在这里找到的等待功能,但该功能不起作用,或者我不知道如何使用它。

window.onload=function() {
    document.getElementById('messages-tab').click()
    messages()
}

function messages(){
document.querySelectorAll(".messageListItem")
for (let i = 0; i < document.querySelectorAll(".messageListItem").length; i++) {
    setTimeout(function () {
        (document.querySelectorAll(".messageListItem")[i].click());
        myfunc()
        parseInfo()
    },[i] * 3000)
    }
}
let matchPhone
let matchInsta
let matchInstagram
let matchInst

function parseInfo() {
    let infoTab=document.querySelector(".BreakWord > div:nth-child(1)").innerText
    matchingInfo(infoTab)

}

function myfunc(){
    const items=document.querySelectorAll('.msgHelper');
    items.forEach(function(text){
        let vi=text.innerText


    matchingInfo(vi)

    })
}


function matchingInfo(text_info){
    matchInsta=text_info.match(instaUsername)
    matchPhone=text_info.match(phoneNumber)
    matchInstagram=text_info.match(instagram)
    matchInst=text_info.match(inst)
    console.log(matchPhone)
    console.log(matchInsta)
    console.log(matchInstagram)
    console.log(matchInst)


}
var phoneNumber= /(?:\+|\d)[\d\-\(\) ]{9,}\d/g
var instaUsername= /\@.*/gmi
var instagram= /nst(.*)/s
var inst= /^[a-zA-Z0-9_][a-zA-Z0-9_.]*/gm





function waitForElementTodisplay(selector,time) {
    if(document.querySelector(selector)!=null) {
        alert("The element is displayed,you can put your code instead of this alert.")
        return;
    }
    else {
        setTimeout(function() {
            waitForElementTodisplay(selector,time);
        },time);
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)