尝试在 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 (将#修改为@)