Giter Site home page Giter Site logo

Comments (6)

a10kiloham avatar a10kiloham commented on May 24, 2024

I'm trying this with evaluate now which I suspect may be a better solution but getting a syntax error:

var test = await browser.evaluate({
    'expression': 'window.location.toString()'
});

returns a syntax error. Looking at the remote interface that seems to be valid syntax? And how do I enable the debug logging?
Cheers

from simple-headless-chrome.

a10kiloham avatar a10kiloham commented on May 24, 2024

Ah, seems that requires a function input. Not sure how to extract data better, but creating a evaluateElement function removing the .apply gives the desired result. Would it make sense to add a function to evaluate simple non-function expressions? This would allow for extracting page elements more easily.

from simple-headless-chrome.

LucianoGanga avatar LucianoGanga commented on May 24, 2024

Hi @bobbysteel !

Regarding the first comment, I didn't code the .getValue() method thinking on how to get the text between HTML tags; it was made to get HTML Form elements values. I think that for that case, it's better to get it using .evaluate(), which refers also to your second message:

The correct way to use the .evaluate method is this:

const location = await browser.evaluate(function(selector) {
    const selectorHtml = document.querySelector(selector) 
    return selectorHtml.innerText
}, '.graph-metric-current');

About the debugging, you just need to start the app setting an environment variable called DEBUG, to the value "HeadlessChrome:[file]', like this:

DEBUG='HeadlessChrome:actions' npm start

or:

DEBUG='HeadlessChrome:browser' npm start

or, if you want all the logs:

DEBUG='HeadlessChrome:*' npm start

I hope it helps!
Luciano

from simple-headless-chrome.

a10kiloham avatar a10kiloham commented on May 24, 2024

Thanks Luciano. I'm almost there, but in your sample it throws ReferenceError: selector is not defined. I'm probably being really dumb here but what am I missing?

from simple-headless-chrome.

LucianoGanga avatar LucianoGanga commented on May 24, 2024

My example was wrong! haha, sorry!
I just corrected it, can you check it? Tell me if it doesn't work :)

from simple-headless-chrome.

a10kiloham avatar a10kiloham commented on May 24, 2024

MAGIC! Thanks!!!

from simple-headless-chrome.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.