Network Conditions (Throttling) setup requires more attention

Hi, guys! :vulcan_salute:

I have a problem with identifying proper steps to setup network delay (throttling) through the browser opening. I’ve already investigated that solution for my problem exists, but I need additional review/assist from the experts to apply it properly. I feel that final implementation will be very suitable to all, who needs to test their project on slow internet. So, the direct solution is here - selenium.webdriver.chromium.webdriver — Selenium 4.25.0 documentation

def set_network_conditions(self, **network_conditions)

Before writing the request I did “homework” and all my tries lead to errors like to:

  • No keyword with name ‘Set Network Conditions’ found
  • Evaluating expression ‘sys.modules[‘selenium.webdriver’].set_network_conditions(offline=True, latency=100, download_throughput=512, upload_throughput=256)’ failed: AttributeError: module ‘selenium.webdriver’ has no attribute ‘set_network_conditions’
  • InvalidArgumentException: Message: invalid argument: cannot parse capability: goog:chromeOptions from invalid argument: unrecognized chrome option: setNetworkConditions
  • Options object does not have method ‘set_network_conditions’
  • Or browser was opened, but set params were ignored

So, if somebody already faced with such or similar problem or has some ideas how to avoid it - please assist. I’ll be very grateful for any comments! Thanks!

  • Keyword is not found because its not implemented on the SeleniumLibrary side.
  • sys.modules[‘selenium.webdriver’] type of approach would not work either, in this case set_network_conditions is not member of the module you are fetching but even if was, you should get the instance of the class robot has instantiated …
  • network conditions are not part of the chrome options.

Since this looks like a somewhat new feature and also chrome specific, your best option would be to create a plugin SeleniumLibrary that calls set_network_conditon when current webdriver is chrome based.

1 Like