未经手的反射措施:NosuchsessionError:尝试运行命令而不建立连接

发布于 2025-02-06 12:59:47 字数 766 浏览 1 评论 0原文

我试图将selenium-webdrivernodejs一起使用。每件事都变得顺利,但是一旦结束,它就会在终端中出现此错误。这是什么问题。

无用的征服者:NosuchsessionError:试图运行 命令而不建立连接。

这是我的代码,

let webdriver = require('selenium-webdriver');
const { Builder, Key, until } = require('selenium-webdriver');

By = webdriver.By;

let driver = new webdriver.Builder().forBrowser('firefox').build();

driver.get('https://www.google.com/');

pause(2, ScraperExample);

function ScraperExample() {
  console.log('Scrapping the Pagee...');

  pause(3, QuitDriver);
}

function pause(Time, FuncName) {
  setTimeout(FuncName, Time * 1000);
}

function QuitDriver() {
  driver.close();
  driver.quit();
  console.log('The Driver is set to off...');
}

I was trying to use selenium-webdriver with nodeJs. Every thing was going smooth but as soon as it end it pop up with this error in terminal.What's wrong in this.

UnhandledPromiseRejectionWarning: NoSuchSessionError: Tried to run
command without establishing a connection.

Here is my code,

let webdriver = require('selenium-webdriver');
const { Builder, Key, until } = require('selenium-webdriver');

By = webdriver.By;

let driver = new webdriver.Builder().forBrowser('firefox').build();

driver.get('https://www.google.com/');

pause(2, ScraperExample);

function ScraperExample() {
  console.log('Scrapping the Pagee...');

  pause(3, QuitDriver);
}

function pause(Time, FuncName) {
  setTimeout(FuncName, Time * 1000);
}

function QuitDriver() {
  driver.close();
  driver.quit();
  console.log('The Driver is set to off...');
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍白女子 2025-02-13 12:59:47

我找到了我自己问题的解决方案之一,我们可以使用此drive.close()driver.quit()来解决它。被使用比我们将面临的问题。

function QuitDriver() {
  driver.quit();
  console.log('The Driver is set to off...');
}```

I found one of the solution for my own question, we can resolve it by using any one of this drive.close() or driver.quit() if both of going to be used than we will face issues.

function QuitDriver() {
  driver.quit();
  console.log('The Driver is set to off...');
}```
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文