如何解决尝试在 worker_thread 中运行 selenium-webdriver 时出错
我在一个班级中运行 selenium 作业:
class SomeClass {
construnctor() {
this.capabilities = Capabilities.chrome();
this.capabilities.set(Capability.ACCEPT_INSECURE_TLS_CERTS,true);
this.capabilities.set(Capability.broWSER_NAME,'chrome');
this.chromeOptions = new Options();
this.chromeOptions.addArguments('headless');
this.chromeOptions.addArguments('--disable-dev-shm-usage') ;
this.chromeOptions.excludeSwitches('enable-logging');
}
someFunction = async () => {
this.driver = await new
Builder().withCapabilities(this.capabilities).forbrowser('chrome').setChromeOptions(this.chromeOptions)
.build(); // here is where it fails
... // rest of the code
}
}
它运行得很好,但是当我把它放在一个 worker_thread 中时,我得到了这个错误:
Cannot read property 'split' of undefined at Object.exports.findInPath (..node_modules\selenium-webdriver\io\index.js)
好像和驱动有关。
更新:
我想出了问题。从工作线程内部,无法访问 process.env.PATH。当我使用 webdriver 的位置更新工作线程本身内部的 PATH 时,它可以工作。有人可以帮我理解为什么它无法访问本地系统环境变量以及解决它的正确方法是什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。