I am trying to use puppeteer to type hello world in a discord web browser chatbox

32 views Asked by At

The problem is with selecting the div it always times out when i try to select the div. Has anyone else It seems like it has several nested divs is there are way of finding out the exact div im looking for?


async function run() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();

    try {
        // Navigate to the page with the target div
        await page.goto('https://discord.com/channels/1208249628953153547/1208245629469048914');

        // Wait for the div to be present
        const divSelector = 'class="placeholder_e68c63 slateTextArea__0661c fontSize16Padding__48818"';
        await page.waitForSelector(divSelector, { timeout: 5000 });

        // Click on the textbox within the span inside the div
        const inputSelector = `${divSelector} [data-slate-node="text"] input[type="text"]`; // Replace with the correct input type
        await page.click(inputSelector);

        // Type a message into the input field
        await page.type(inputSelector, 'Hello, this is my message!');

        // Press Enter to send the message (optional)
        await page.keyboard.press('Enter');

        // Wait for a while to see the result (you can adjust the duration)
        await page.waitForTimeout(2000);
    } catch (error) {
        console.error('Error:', error.message);
    } finally {
        await browser.close();
    }
}

run();
0

There are 0 answers