sambaiz / puppeteer-lambda-starter-kit

Starter Kit for running Headless-Chrome by Puppeteer on AWS Lambda.
MIT License
580 stars 82 forks source link

Not getting element when executing on Lambda #41

Open nei opened 5 years ago

nei commented 5 years ago

Hi, could anyone explain the main differences when running local vs on lambda?

It seems when running on Lambda it cannot find the elements but when I run local it does work.

Local Nodejs: v8.10.0 runtime: nodejs8.10

So, I would like to understand how to debug this properly.

{
    "errorMessage": "Node is either not visible or not an HTMLElement",
    "errorType": "Error",
    "stackTrace": [
        "ElementHandle.<anonymous> (/var/task/node_modules/puppeteer/node6/lib/ExecutionContext.js:635:13)",
        "next (native)",
        "step (/var/task/node_modules/puppeteer/node6/lib/ExecutionContext.js:610:24)",
        "Promise.resolve.then.value (/var/task/node_modules/puppeteer/node6/lib/ExecutionContext.js:621:15)",
        "process._tickDomainCallback (internal/process/next_tick.js:135:7)"
    ]
}

My code looks like this:

async login(page, url) {
        console.log('login on '+url);
        await page.goto(url, {waitUntil: 'networkidle0'});
        await page.waitFor(1 * 1000);
        const LOGIN = await page.$x('//*[@id="loginForm"]/div[1]/input');
        console.log(LOGIN);
        if (LOGIN.length > 0) {
            await LOGIN[0].click();
        }
    };

I I've printed the element to make sure it was finding on the page. here is the output.

2018-11-11T17:18:31.416Z    2f2ebb24-4837-5f9e-b625-ef462ebab245    [ ElementHandle {
_context: 
ExecutionContext {
_client: [Object],
_frame: [Object],
_contextId: 2,
_isDefault: true },
_client: 
CDPSession {
domain: null,
_events: [Object],
_eventsCount: 27,
_maxListeners: undefined,
_lastId: 133,
_callbacks: Map {},
_connection: [Object],
_targetType: 'page',
_sessionId: '19D40695F65E926625F0B1A1C1FF03FC:1',
_sessions: Map {} },
_remoteObject: 
{ type: 'object',
subtype: 'node',
className: 'HTMLInputElement',
description: 'input.font-size-1.col-12.ng-pristine.ng-untouched.ng-valid.ng-empty',
objectId: '{"injectedScriptId":2,"id":7}' },
_disposed: false,
_page: 
Page {
domain: null,
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
_closed: false,
_client: [Object],
_target: [Object],
_keyboard: [Object],
_mouse: [Object],
_touchscreen: [Object],
_accessibility: [Object],
_networkManager: [Object],
_frameManager: [Object],
_emulationManager: [Object],
_tracing: [Object],
_pageBindings: Map {},
_ignoreHTTPSErrors: false,
_coverage: [Object],
_javascriptEnabled: true,
_viewport: [Object],
_screenshotTaskQueue: [Object],
_workers: Map {} },
_frameManager: 
FrameManager {
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
_client: [Object],
_page: [Object],
_networkManager: [Object],
_defaultNavigationTimeout: 30000,
_frames: [Object],
_contextIdToContext: [Object],
_mainFrame: [Object] } } ]
iamsaso commented 5 years ago

I'm also getting different behavior. Did anyone find out why this is happening?

nei commented 5 years ago

I basically gave up on this. It seems the node are different or at least wrapped in some sort. I will give another try on https://github.com/lambci/docker-lambda to see if I can debug.