如何使用JavaScript在Selenium中设置网络限制?

时间:2019-03-26 05:02:51

标签: javascript selenium-webdriver selenium-chromedriver

如何使用硒和javascript在chrome中设置网络限制设置

1 个答案:

答案 0 :(得分:1)

我也花了一些时间来解决这个问题,但这似乎对我有用

  driver = await new Builder()
            .forBrowser(engine)
            .usingServer(testConfig.seleniumServer + 'wd/hub')
            .setChromeOptions(new chrome.Options()) //.headless()
            .build();
        driver.setNetworkConditions({
            offline: false,
            latency: 15, // Additional latency (ms).
            download_throughput: 50 * 1024, // Maximal aggregated download throughput.
            upload_throughput: 50 * 1024 // Maximal aggregated upload throughput.
        });