gpt4 book ai didi

node.js - 为什么我在使用 selenium chromedriver 时会出现此错误?

转载 作者:太空宇宙 更新时间:2023-11-04 01:49:27 25 4
gpt4 key购买 nike

当执行下面的代码时,它会打开 chrome,并且搜索栏已填充此 data;,。我没有在代码中的任何地方提到它,但这种情况仍然发生。而且,每次我尝试运行代码时都很少出现错误。

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;
}

我收到此错误

 (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

如何删除它?

最佳答案

在向搜索栏发送按键之前,使用 .clear(); 清除搜索栏的输入字段。有关它的详细信息,请参阅此问题的答案 question .

Promise 不会用 catch 来处理拒绝。遵循另一个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!");
});

关于node.js - 为什么我在使用 selenium chromedriver 时会出现此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50267753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com