Skip to content
This repository has been archived by the owner on Jun 20, 2020. It is now read-only.

I cannot login with tab.fill #21

Closed
man0l opened this issue Jan 9, 2018 · 4 comments
Closed

I cannot login with tab.fill #21

man0l opened this issue Jan 9, 2018 · 4 comments

Comments

@man0l
Copy link

man0l commented Jan 9, 2018

Hi,
thank you for your time in advance.

I am having login issue with nickjs.

I took the cookies from my browser and I set it up before opening the URL.

This is my code. As you can see from the screenshot, it fills the email and the password (the "name" attributes are the same with the input's keys) but it stops there (you can see my shell console output bellow).

I tried to navigate to a url which requires log-in, but it gives me the login form again, which means the login process wasn't successfull.

Would you help me to solve this issue? I would appreciate your help.

Regards,
Manol.

`
const selector = "form[name='signIn']";
const inputs = {
'email': "real email",
'password': "real password"
};

try {
  await tab.waitUntilVisible(selector, 5000)
  await tab.fill(selector, inputs, { submit: true })
  //await tab.click("input#signInSubmit")
  console.log("Form sent!")
  await tab.screenshot('./login.png')

} catch (err) {
  console.log("Form not found:", err)
}`

login

`root@06131ed62a3b:/app# node index.js

Fatal: Chrome subprocess exited with code 1

Tab 1: Navigation (open): https://www.amazon.com/ap/signin?_encoding=UTF8&accountStatusPolicy=P1&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fcss%2Forder-history%3Fie%3DUTF8%26ref_%3Dnav_youraccount_orders&pageId=webcs-yourorder&showRmrMe=1
Tab 1: Navigation (formSubmissionPost): https://www.amazon.com/ap/signin
Form sent!
Job done!
`

@TASnomad
Copy link

TASnomad commented Jan 9, 2018

Hi @man0l,

Could you add between your await tab.fill() and await tab.screenshot() a call of await tab.wait(5000) ?

After running some test with the given code, i faced to a captcha (after calling await tab.wait(5000)).

Could you tell me, if you got the same result with this ?

Regards,

Martin B.

@man0l
Copy link
Author

man0l commented Jan 9, 2018

You're right, @TASnomad, I get captcha!

Thank you for your reference!

This means the cookies are not set correctly and the fill() method works correctly :)

I have similar script in casperjs and when I enabled the cookies, I was able to log-in.

I am new with headless google chrome, how can I pass the cookies correctly?
When I dump the result from nick.getallCookies() it gives me this:

Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }

@TASnomad
Copy link

TASnomad commented Jan 9, 2018

@man0l , If you use the current version of Nickjs you can call nick.setCookie() to set a cookie in chrome headless.

The functions setCookies() and getAllCookies() return a Promise object, that's why in your trace, you get a Promise object and not the expected result. :)

setCookies() takes an object which looks like:

{
  name: 'cookie name',
  value: 'value cookie',
  domain: '.website.domain'
}

And code snippets could look like the follow examples:

try {
  await nick.setCookie({name: 'cookie name', value: 'value cookie', domain: '.website.domain'})
} catch (e) {
  console.log(`Error:`, e)
}

or :

await nick.setCookie({name: 'cookie name', value: 'value cookie', domain: '.website.domain'})
.then(() => {})
.catch((err) => {})

@paps paps closed this as completed Jan 11, 2018
@man0l
Copy link
Author

man0l commented Jan 11, 2018

Thank you for your reply, Tas!
I've managed to login with real pre-set cookies.

Regards,
Manol.

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

No branches or pull requests

3 participants