Quick actions

cmd+k|ctrl+k

Navigation

Languages

jquery $x xpath

Snippet info

Language

Cpp

Visibility

public

Author

awesome2023

Created

2025-12-12T14:12:41.558977Z

Updated

2025-12-12T14:12:41.558977Z

//div[@class="product-list"]/div[@data-price > 3000]


chrome 中使用 $x,比jquery更好玩

https://www.cnblogs.com/xiongbatianduxing/p/19085925

// 使用JavaScript等待元素出现
function waitForElement(xpath, timeout = 5000) {
    const startTime = new Date().getTime();
    return new Promise((resolve, reject) => {
        const checkExist = setInterval(() => {
            const element = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
            if (element) {
                clearInterval(checkExist);
                resolve(element);
            } else if (new Date().getTime() - startTime > timeout) {
                clearInterval(checkExist);
                reject(new Error(`元素未在${timeout}ms内出现: ${xpath}`));
            }
        }, 100);
    });
}

// 使用方法
waitForElement('//div[@id="dynamic-content"]')
    .then(element => console.log('找到元素:', element))
    .catch(error => console.error(error));
INFO