当执行下面的代码时,它会打开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();
清除搜索栏的输入字段。有关它的详细信息,请参阅此问题的答案。
承诺不是用捕获来处理拒绝。在另一个关于拒绝承诺的问题的回答之后。
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!");
});