LucianoGanga / simple-headless-chrome

Simple abstraction to use Chrome as a Headless Browser with Node JS
MIT License
217 stars 50 forks source link

How to get values from the iframe ? #61

Open collegepinger opened 7 years ago

collegepinger commented 7 years ago

How to get whole document body value which is inside iframe But it returns me nothing

const HeadlessChrome = require('simple-headless-chrome');

const browser = new HeadlessChrome({
    headless: false // If you turn this off, you can actually see the browser navigate with your instructions
    // see above if using remote interface
});

async function navigateWebsite() {
    try{
        await browser.init()

        const mainTab = await browser.newTab({ privateTab: false })

        await mainTab.goTo('http://someSiteIframe.com');

        let frames = await mainTab.getFrames()
        await mainTab.wait(2000);

        let sampleId = frames[1].id;

        console.log(sampleId)

        mainTab.getValue('document.body',`${sampleId}`).then(data => {
            console.log(data,sampleId,"From frame")
        });

        const htmlTag = await mainTab.evaluate(function(selector) {
            return document.querySelector(selector)

        }, '.slave-0-1');

        await browser.close()

    }catch (err){
        console.log('ERROR!', err)
    }
}

navigateWebsite()
LucianoGanga commented 7 years ago

Hi @collegepinger !

Sorry for the late reply. Can you give me the URL of the site you're trying to get the value from?

So I can help you with the code.

Thanks! Lucho

LucianoGanga commented 7 years ago

Hi @collegepinger !

Could you fix the issue?

Thanks! Luciano