Why am I getting this error with selenium chromedriver? - node.js

When the code below is executed it opens chrome and the search bar is filled already with this data;,. I haven't mentioned it anywhere in the code still this happens.
Moreover, there are few errors that appear each time I try to run the code.
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver =new webdriver.Builder()
.forBrowser('chrome')
.build();
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('wiki');
driver.findElement(By.name('btnG')).click();
driver.wait(check_title,1000);
function check_title(){
var promise = driver.getTitle().then((title)=>{
if(title === 'wiki - Google Search'){
console.log('success!');
return true;
}else{
console.log("failed!!");
}
});
return promise;
}
I get this error
(node:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227
(node:15384) [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.
(node:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227
(node:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227
(node:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227
(node:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227
How can this be removed?

Use .clear(); to clear the input field for the search bar before you send keys to it. For details on what it does see the answer to this question.
The Promise is not handling the reject with a catch. Following the answers from another question on promise rejection.
var promise = driver.getTitle().then((title)=>{
if(title === 'wiki - Google Search') {
console.log('success!');
return true;
} else {
console.log("failed!!");
}
}).catch(function () {
console.log("Promise Rejected!");
});

Related

not getting the ops array after inserting into mongo db

when am trying to move the image after inserting into mongo db using the function
var db = require('../config/dbconnect')
module.exports = {
//addProduct:(product,callback)=>
addProduct: (product, callback) => {
//console.log(product)
db.get().collection('product').insertOne(product).then((data) => {
console.log(data)
callback(data.ops[0]._id)
})
}
}
I am getting an error like:
{
acknowledged: true,
insertedId: new ObjectId("61054e43cffb994774d37ab0")
}
(node:6964) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
at E:\Nodejs\ecommerce\helpdesk\product_help.js:11:27
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6964) 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: 1)
(node:6964) [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 is error first callback. Try the second argument which is the result.
db.get().collection('product').insertOne(product).then((error,data)=>
{
console.log(data)
callback(data.ops[0]._id)
})
instead of callback(data.ops[0]._id).
Try:
db.get().collection('product').insertOne(product).then((data) => {
callback(data.insertedId)
})
.catch((err)=>console.log('venk error',err))
}

Node.js Problem with puppeteer headless:True : " Evaluation failed: TypeError: Cannot read property 'querySelectorAll' of null"

My code works perfectly well with headless false, but when I change it to true I get this error :
(node:92024) UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: Cannot read property 'querySelectorAll' of null
at __puppeteer_evaluation_script__:7:17
at ExecutionContext._evaluateInternal (C:\wamp64\www\scrappingWithNodejs\testDiscordBot\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:221:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async ExecutionContext.evaluate (C:\wamp64\www\scrappingWithNodejs\testDiscordBot\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:110:16)
at async getAllInfos (C:\wamp64\www\scrappingWithNodejs\testDiscordBot\index.js:28:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:92024) 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: 1)
(node:92024) [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.
My code :
async function getAllInfos() {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
page.setDefaultNavigationTimeout(0);
await page.goto(`https://www.japanread.cc/`, {
waitUntil: ["load", "domcontentloaded", "networkidle0", "networkidle2"],
}); //se rendre sur une page
let trs = [];
trs = tbody.querySelectorAll("tr");//the error is here
I tried to put showMo, put several things in the "waitUntil" but I get nothing, I really don't understand.
Do you know what the problem is?

NestJS UnhandledPromiseRejectionWarning by Promise

when running my Get method in both Swagger and Postman, I get the following error message:
(node:35014) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'error' of null
at HttpErrorFilter.catch (/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/src/shared/http-error.filter.ts:28:31)
at ExceptionsHandler.invokeCustomFilters (/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/node_modules/#nestjs/core/exceptions/exceptions-handler.js:31:26)
at ExceptionsHandler.next (/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/node_modules/#nestjs/core/exceptions/exceptions-handler.js:12:18)
at /Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/node_modules/#nestjs/core/router/router-proxy.js:12:35
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:35014) 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:35014) [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.
d.service.ts
public async getCorporateDesignByDistrictName(name: string): Promise<CorporateDesign> {
const district: District = await this.districtRepository.createQueryBuilder('district')
.leftJoinAndSelect('district.mandant', 'mandant')
.leftJoinAndSelect('district.corporateDesign', 'corporateDesign')
.where('district.name = :name')
.andWhere('district.isDeleted = :isDeleted')
.setParameters({
name: name,
isDeleted: false
})
.getOne();
return district.corporateDesign;
}
d.controller.ts
#UseGuards(AuthGuard)
#Get(':name')
public async getCorporateDesignByDistrictName(#Param('name') name: string): Promise<CorporateDesign> {
return this.districtService.getCorporateDesignByDistrictName(name);
}
I'm using angular 8 and nest.js

bug in connection to cluster mongodb

i'm using nodejs to connect to mongodb and i get this error
i added the IP and nothing happend
(node:7412) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 5 to cluster0-shard-00-02-xobf0.mongodb.net:27017 closed
at TLSSocket.<anonymous> (C:\Users\user\Desktop\NodeJS - The Complete Guide\node_modules\mongodb-core\lib\connection\connection.js:352:9)
at Object.onceWrapper (events.js:277:13)
at TLSSocket.emit (events.js:189:13)
at _handle.close (net.js:597:12)
at TCP.done (_tls_wrap.js:388:7)
(node:7412) 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:7412) [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.
[nodemon] clean exit - waiting for changes before restart
Try this ,
const MongoClient = require("mongodb").MongoClient;
const uri ="mongodb+srv://user:userpassword#meanapp-srlw9.mongodb.net/test?retryWrites=true";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
const collection = client.db("test").collection("devices");
// perform actions on the collection object
console.log("connencted");
client.close();
});
For now, change your cluster setting to connect from anywhere

Selenium example using Node.js from MDN not working?

I have been trying to work with the Selenium example from this page: https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Your_own_automation_environment.
I have done the following steps:
Set up a new npm project
Install the selenium webdriver using npm install selenium-webdriver
I've also gotten the GeckoDriver and ChromeDriver and added them to my PATH.
Then I created a local copy of the example google_test.js (shown below) and ran it using the command node google_test.
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.sleep(1000).then(function() {
driver.findElement(By.name('q')).sendKeys(webdriver.Key.TAB);
});
driver.findElement(By.name('btnK')).click();
driver.sleep(2000).then(function() {
driver.getTitle().then(function(title) {
if(title === 'webdriver - Google Search') {
console.log('Test passed');
} else {
console.log('Test failed');
}
});
});
driver.quit();
My problem is that for me, the example above only opens a new Firefox instance, and immediately closes without performing any actions.
After running the command node google_test I get the error messages below:
(node:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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:23652) [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.
(node:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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: 2)
(node:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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)
(node:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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: 5)
(node:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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: 6)
My package.json file is:
{
"name": "selenium-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"selenium-webdriver": "^4.0.0-alpha.1"
}
}
Could anyone please assist me?

Resources