Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getValue returns undefined #6

Closed
a10kiloham opened this issue Jun 11, 2017 · 6 comments
Closed

getValue returns undefined #6

a10kiloham opened this issue Jun 11, 2017 · 6 comments

Comments

@a10kiloham
Copy link
Contributor

a10kiloham commented Jun 11, 2017

Hm. Not sure if this is my error or a bug.

Using getValue returns undefined for a valid element.

  // <div class="graph-metric-current">Test</div>
    var alpha = await browser.getValue('.graph-metric-current')
    console.log(alpha)

The returned should be a HTML value of the .graph-metric-current node shouldn't it? Using util.inspect also returns undefined, so I'm not quite sure what the object is meant to be.

Cheers

@a10kiloham
Copy link
Contributor Author

a10kiloham commented Jun 12, 2017

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

@a10kiloham
Copy link
Contributor Author

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.

@LucianoGanga
Copy link
Owner

LucianoGanga commented Jun 12, 2017

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

@a10kiloham
Copy link
Contributor Author

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?

@LucianoGanga
Copy link
Owner

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

@LucianoGanga LucianoGanga reopened this Jun 12, 2017
@a10kiloham
Copy link
Contributor Author

MAGIC! Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants