bitshiftza / fnb-api

Pull account balances and transactions from FNB online banking.
GNU General Public License v3.0
58 stars 27 forks source link

Error: No element found for selector: #user #20

Open AntonJanHart opened 8 months ago

AntonJanHart commented 8 months ago

fnb@ftp:~/api$ node main.js Error: No element found for selector: #user at assert (/home/fnb/api/node_modules/fnb-api/node_modules/puppeteer-core/lib/cjs/puppeteer/util/assert.js:28:15) at IsolatedWorld.type (/home/fnb/api/node_modules/fnb-api/node_modules/puppeteer-core/lib/cjs/puppeteer/common/IsolatedWorld.js:221:32) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

fnb@ftp:~/api$ npm list fnb-api fnb-api-master@1.0.9 /home/fnb/api └── fnb-api@1.0.11

fnb@ftp:~/api$ npm show puppeteer-core version 22.0.0

AntonJanHart commented 8 months ago

DevTool shows: <input type="text" placeholder="Username" id="user" name="Username" value="" tabindex="1" class=" userName"> <input type="password" placeholder="Password" id="pass" name="Password" value="" tabindex="2" class=" passWord">

AntonJanHart commented 8 months ago

I think I fixed this by changing submit button. src/scrapers/scraper.ts

// await this._page.click('input[type="submit"]') await this._page.click('#OBSubmit');

echo909 commented 8 months ago

I think I fixed this by changing submit button. src/scrapers/scraper.ts

// await this._page.click('input[type="submit"]') await this._page.click('#OBSubmit');

This fixed the login for me, pls update repo

circlingthesun commented 8 months ago

@AntonJanHart @echo909 thats unlikely what fixed it. The reason why #user is not found is because FNB now has some kind of DDOS protection, that shows up:

image

You'll see It appears the first time the site loads, then a cookie gets set and the page reloads. You can see it by clearing your cookies on FNB and reloading the page with javascript disabled.

I'm going to try add this before trying to type in a username:

await this._page.waitForSelector('#user', { timeout: 30000 });

circlingthesun commented 8 months ago

That does not appear to work

circlingthesun commented 8 months ago

Upon further inspection: image

The capcha doesn't show up on my local.

circlingthesun commented 8 months ago

K, so I worked around this by using 'puppeteer-extra-plugin-recaptcha' and 2captcha.

See: https://www.zenrows.com/blog/puppeteer-captcha-bypass#solver-plugin

image
AntonJanHart commented 2 months ago

My case I didn't get a capcha, but the "verifing your browser", where setting user agent did the trick:

(async () => {
  const customUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36';
  const api = new FnbApi({
    username: 'username',
    password: 'password',
    puppeteerOptions: {
      args: [
        '--user-agent=${customUserAgent}'
      ],
    }
  });