So today I am using a node framework called puppeteer which basically controls all aspects of your browser. I am trying to make a checkout bot but I am getting an error while trying to navigate to the other page. I am using Nike for this example. Here is the error shown:
^
Error: No node found for selector: #f25e2320-d66d-48f3-88b3-cd92f4c5c1cd
at exports.assert (C:\Users\Shushan\Desktop\firebaseSampleTest\node_modules\puppeteer\lib\cjs\puppeteer\common\assert.js:26:15)
at DOMWorld.type (C:\Users\Shushan\Desktop\firebaseSampleTest\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:306:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async C:\Users\Shushan\Desktop\firebaseSampleTest\index.js:88:29
Node.js v18.3.0
PS C:\Users\Shushan\Desktop\firebaseSampleTest> ^C
PS C:\Users\Shushan\Desktop\firebaseSampleTest> node .
I am ready!
(node:40328) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:40328) DeprecationWarning: Passing strings for MessageEmbed#setAuthor is deprecated. Pass a sole object instead.
C:\Users\Shushan\Desktop\firebaseSampleTest\node_modules\puppeteer\lib\cjs\puppeteer\common\assert.js:26
throw new Error(message);
^
Error: No node found for selector: #f25e2320-d66d-48f3-88b3-cd92f4c5c1cd
at exports.assert (C:\Users\Shushan\Desktop\firebaseSampleTest\node_modules\puppeteer\lib\cjs\puppeteer\common\assert.js:26:15)
at DOMWorld.type (C:\Users\Shushan\Desktop\firebaseSampleTest\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:306:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async C:\Users\Shushan\Desktop\firebaseSampleTest\index.js:88:29
Node.js v18.3.0
PS C:\Users\Shushan\Desktop\firebaseSampleTest>
When I am clicking on the continue to cart button in Nike, it is rerouting me to the login page. The input with the ID #f25e2320-d66d-48f3-88b3-cd92f4c5c1cd is appearantly not showing in the page, but it clearly is. My code files are below:
index.js
const url = 'https://www.nike.com/t/air-max-270-mens-shoes-KkLcGR/DQ7642-100';
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(`${args}`);
await page.click('.wishlist-btn');
page.setDefaultNavigationTimeout( 90000 );
await page.type('#f25e2320-d66d-48f3-88b3-cd92f4c5c1cd', 'Hello World');
})();
Again like I said before, when I click the button on the URL https://www.nike.com/t/air-max-270-mens-shoes-KkLcGR/DQ7642-100, it reroutes the browser to the login page but there Puppeteer is showing me an error that the node is not found. Can someone please help me with this error? Thanks.
Related
i want to run whatsapp-web.js module in replit using node.js
I tried the program in the library documentation. namely as follows
const qrcode = require('qrcode-terminal');
const { Client, LocalAuth } = require('whatsapp-web.js');
const client = new Client({
authStrategy: new LocalAuth()
});
client.on('qr', qr => {
qrcode.generate(qr, { small: true });
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.on('message', async msg => {
const text = msg.body.toLowerCase() || '';
//check status
if (text === '!ping') {
msg.reply('pong');
}
});
client.initialize();
but when run. i get an error like this
/home/runner/coba-puppeteer/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241
reject(new Error([
^
Error: Failed to launch the browser process!
/home/runner/coba-puppeteer/node_modules/whatsapp-web.js/node_modules/puppeteer/.local-chromium/linux-982053/chrome-linux/chrome: error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (/home/runner/coba-puppeteer/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241:20)
at Interface.<anonymous> (/home/runner/coba-puppeteer/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:231:68)
at Interface.emit (node:events:525:35)
at Interface.emit (node:domain:489:12)
at Interface.close (node:readline:590:8)
at Socket.onend (node:readline:280:10)
at Socket.emit (node:events:525:35)
at Socket.emit (node:domain:489:12)
at endReadableNT (node:internal/streams/readable:1358:12)
repl process died unexpectedly: exit status 1
I've found the problem I may be having is that it doesn't have the libraries required by puppeteer on the system. For example, the error message says "libgobject-2.0.so.0" could not be found. It may be a library that puppeteer needs to run. try installing the required libraries by running the following command in your terminal: sudo apt-get install libgobject-2.0-0
however replit cannot use sudo command
with error sudo: The "no new privileges" flag is set, which prevents sudo from running as root.
has anyone ever managed to run a program using whatsapp-web.js in replit?
i am very confused what should i do
the expected output is that it will print the qrcode from whatsapp on the terminal
This question already has answers here:
Why am I getting a ReferenceError: AbortController is not defined in Discord.js v13?
(3 answers)
Closed 1 year ago.
const {Client, Intents} = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.login(token);
I have this code, every time i try to run it returns me the same error:
(node:13284) UnhandledPromiseRejectionWarning: ReferenceError:
AbortController is not defined
at RequestHandler.execute (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\rest\RequestHandler.js:172:15)
at RequestHandler.execute (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\rest\RequestHandler.js:176:19)
at RequestHandler.push (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\rest\RequestHandler.js:50:25)
at async WebSocketManager.connect (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\client\websocket\WebSocketManager.js:128:9)
at async Client.login (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\client\Client.js:245:7)
(Use node --trace-warnings ... to show where the warning was
created) (node:13284) UnhandledPromiseRejectionWarning:
Unhandled promise rejection. This error originated either by throwing
inside of an async function without a catch block, or by rejecting a
promise which was not handled with .catch(). To terminate the node
process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict (see
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).
(rejection id: 2) (node:13284) [DEP0018] DeprecationWarning: Unhandled
promise rejections are deprecated. In the future, promise rejections
that are not handled will terminate the Node.js process with a
non-zero exit code.
Dont know how to fix it. I tried and investigate on the documentation but cant find the solution.
I've added this line to my code to find the error:
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
Getting this:
{ code: 500, method: 'get', path: '/gateway/bot', requestData:
{ json: undefined, files: [] } }
The AbortController package was introduced in Node.js v16 (?). So you need to upgrade your Node.js version. Discord.js v13 requires you to use Node.js v16 and higher as stated in their documentation.
Depending on your operating system, you can either install 64bits or 32bits version of Node.js. Head over to the official website and download 16.8.x (Current, Latest Features) Windows installer.
After installation, verify the version by typing node -v in your console.
I'm learning about puppeteer and firebase at the moment. What I am trying to do is create a pdf of a web page and upload to firebase storage. This is my code.
const puppeteer = require('puppeteer');
const fs = require('fs').promises;
const firebase = require('firebase');
require("firebase/storage");
const url = process.argv[2];
if (!url) {
throw "Please provide URL as a first argument";
}
var firebaseConfig = {
#Firebase Config Goes here
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
#Function to generate PDF file
async function run () {
const browser = await puppeteer.launch();
const page = await browser.newPage();
//await page.goto(url);
await page.goto(url, {waitUntil: 'domcontentloaded', timeout: 60000} );
//await page.pdf({ path: 'api.pdf', format: 'A4' })
const myPdf = await page.pdf();
await browser.close()
return myPdf;
}
const myOutput = run();
#Upload to Firebase based on the instruction here https://firebase.google.com/docs/storage/web/upload-files
var storageRef = firebase.storage().ref();
// Create a reference to 'mountains.jpg'
storageRef.child(myOutput).put(myOutput)
However, I'm running into this error when executing my code
$ node screenshot.js https://en.wikipedia.org/wiki/Aung_San_Suu_Kyi
C:\Users\ppham\NucampFolder\Test\node_modules\#firebase\storage\dist\index.cjs.js:1040
.split('/')
^
TypeError: childPath.split is not a function
at child (\Test\node_modules\#firebase\storage\dist\index.cjs.js:1040:10)
at getChild (\Test\node_modules\#firebase\storage\dist\index.cjs.js:2610:19)
at ReferenceCompat.child (Test\node_modules\#firebase\storage\dist\index.cjs.js:2833:25)
at Object.<anonymous> (C:\Users\ppham\NucampFolder\Test\screenshot.js:55:12)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
at internal/main/run_main_module.js:17:11
It is saying that childPath.split is not a function. I'm pretty confused at this since I've already installed all the firebase packages. I've been searching for this error for a while but no luck so far. Anyone knows how to resolve this issue?
===============================================================================
Edit #1: As Frank pointed out below, I have to change storageRef.child(myOutput).put(myOutput) to something like storageRef.child("filename.pdf").put(myOutput). It runs but I'm running into this error afterwards.
$ node screenshot.js https://google.com
Promise { <pending> }
(node:20636) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'byteLength' of undefined
at C:\Users\ppham\NucampFolder\Test\node_modules\#firebase\storage\dist\index.cjs.js:833:40
at Array.forEach (<anonymous>)
at Function.FbsBlob.getBlob (C:\Users\ppham\NucampFolder\Test\node_modules\#firebase\storage\dist\index.cjs.js:832:25)
at multipartUpload (C:\Users\ppham\NucampFolder\Test\node_modules\#firebase\storage\dist\index.cjs.js:1519:24)
at C:\Users\ppham\NucampFolder\Test\node_modules\#firebase\storage\dist\index.cjs.js:2003:31
at C:\Users\ppham\NucampFolder\Test\node_modules\#firebase\storage\dist\index.cjs.js:1900:21
at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:20636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:20636) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
This looks to imply that myOutput doesn't contain anything. I thought that I have return the pdf in the run function and it will be passed over to the upload function? I've been reading the Puppeteer documentation and couldn't find any reason why this wouldn't work. Anyone knows why this is not valid?
The error message is saying that the value you're passing to child() is not a string.
Since you're calling:
storageRef.child(myOutput).put(myOutput)
That kind'of makes sense. My guess is that you want to pass a file name into child(), like:
storageRef.child("filename.pdf").put(myOutput)
I am using request to access data from an api. sometimes, when the api Url is down, node throws error and shuts down with the following error
at ClientRequest.emit (events.js:315:20)
at TLSSocket.socketErrorListener (_http_client.js:426:9)
at TLSSocket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: APIURL
is there any way to handle this and prevent node from exiting?
my code is
const JSONdata= ()=>{
request({url:API_URL2,json:true},(error,response,body)=>{
const data=[]
var jsondata=body
data.push(jsondata)
const data2=JSON.stringify(data)
fs.writeFile('sample.txt',data2,(err) => { if(error){console.log(error} })})
You can use try/catch blocks that will keep your program running when certain functions error out. Here's a link describing how they work!
https://www.w3schools.com/js/js_errors.asp
Firstly request module has been deprecated request deprecated hence you can try some other packages like axios. Also while trying out api as well as database request try to have a try and catch block and in case of error try to have an appropriate error message displayed to the user.
try{
//your code
res.json("success")
}
catch(err){
res.json("Looks like something went wrong")
}
I am trying to do a mouse click base on position. However, I can't seem to make action work an always get the following message. I reproduced the problem by trying to double click on google.com main search bar.
For help, see: https://nodejs.org/en/docs/inspector
(node:38864) UnhandledPromiseRejectionWarning: UnknownCommandError: Unrecognized command: actions
warning.js:18
at buildRequest (c:\GitRepo\MMT4\src\javascript\Web.Tests\node_modules\selenium-webdriver\lib\http.js:375:9)
at Executor.execute (c:\GitRepo\MMT4\src\javascript\Web.Tests\node_modules\selenium-webdriver\lib\http.js:455:19)
at Driver.execute (c:\GitRepo\MMT4\src\javascript\Web.Tests\node_modules\selenium-webdriver\lib\webdriver.js:696:38)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:38864) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
warning.js:18
(node:38864) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
imported the packages with npm
"devDependencies": {
"#types/node": "^10.12.0"
},
"dependencies": {
"chromedriver": "^2.43.0",
"selenium-webdriver": "^4.0.0-alpha.1"
}
According to the documentation I found here, it should to work
https://seleniumhq.github.io/selenium/docs/api/javascript/index.html
https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/input_exports_Actions.html
Also found different example on web which support it should work, but cannot see what is missing in this basic example:
"use strict";
require('chromedriver');
const { Builder, By, Key, until, ActionSequence } = require('selenium-webdriver');
(async function run() {
let driver = await new Builder().forBrowser('chrome').build();
try {
await driver.get('http://www.google.com');
await driver
.actions()
.doubleClick(By.id('lst-ib'))
.perform();
}
finally {
await driver.quit();
}
})();
Also tested in a project with protractor and it seem to work, but I don't see why I would need protractor in this project since it does not use Angular.
Thanks
I found solution
i tried downgrade selenium-webdriver version 3.6.0
then, maybe it's possible working
and keydown method only 4 ways execute(i need use keyboard!)
key.CONTROL
key.SHIFT
key.ALT
key.COMMAND
so if you need another keyboard action, use sendKeys method(i used Tab key)
here i referenced link
https://github.com/SeleniumHQ/selenium/issues/5428