Selenium: [Python][Chrome] Vendor specific commands not available with Remote webdriver

Created on 28 Jul 2018  路  5Comments  路  Source: SeleniumHQ/selenium

Meta -

OS:
Linux
Selenium Version:
3.13, Python bidings
Browser:
Chrome

Browser Version:
ChromeDriver 2.40.565383, Chrome 66

Expected Behavior -

set_network_conditions and get_network_conditions work properly and in the same way on local and remote browsers.

Actual Behavior -

For remote Chrome browsers an exception is thrown:
AttributeError: 'WebDriver' object has no attribute 'set_network_conditions'

Steps to reproduce -

from selenium.webdriver import Remote, Chrome

# works fine locally
Chrome().set_network_conditions(latency=5, throughput=5000)

# should also work on selenium/standalone-chrome Docker image on localhost:4444/wd/hub
caps = desired_capabilities={'browserName':'chrome'}
Remote(desired_capabilities=caps).set_network_conditions(latency=5, throughput=5000)

Traceback (most recent call last):
  File "<input>", line 1, in <module>
    Remote(desired_capabilities=caps).set_network_conditions(latency=5, throughput=5000)
AttributeError: 'WebDriver' object has no attribute 'set_network_conditions'

What is the correct way to implement it?

C-py

All 5 comments

got the same error, but when i use local chrome got this message

  • i don't know yet if it's my combination of chrome driver version + selenium version problem
    or if it's selenium problem...
  • for examples im using my own selenium wrapper for python , so... ignore not selenium code.
  • for examples im using this chrome driver files for all SO : https://github.com/netzulo/qadrivers/tree/v0.0.7#chrome

  • [x] FAILED Testcase: open selenium browser using mode local , driver chrome and execute set_network_conditions with params latency=5, throughput=5000

  • [x] FAILED Testcase: open selenium browser using mode remote , driver chrome and execute set_network_conditions with params latency=5, throughput=5000

Local chrome example

from qacode.core.bots.bot_base import BotBase
from qacode.core.webs.controls.control_base import ControlBase
SETTINGS = {
    "bot": {
        "log_output_file": "./",
        "log_name": "selenium-issue6217",
        "log_level": "DEBUG",
        "mode": "local",
        "browser": "chrome",
        "options": {"headless": False},
        "url_hub": "http://localhost:11000/wd/hub",
        "drivers_path": "../qadrivers/",
        "drivers_names": ["chromedriver_64.exe"]
    }
}
bot = None
try:
    bot = BotBase(**SETTINGS)
    import pdb; pdb.set_trace() # TODO, remove DEBUG lane
    # TEST
    bot.curr_driver.set_network_conditions(latency=5, throughput=5000)
    # END
    import pdb; pdb.set_trace() # TODO, remove DEBUG lane
except Exception as err:
    print("ERROR: {}".format(err))
finally:
    bot.close()
  • local chrome log
(qacode) D:\4.developmentWorkSpaces\1.GITHUB\qalab\modules\qacode>python delete_me.py
2018-07-29 14:56:54,667 - selenium-issue6217 - DEBUG - Starting browser with mode : LOCAL ...
[33336:33096:0729/145657.877:ERROR:install_util.cc(589)] Unable to create registry key HKLM\SOFTWARE\Policies\Google\Chrome for reading result=2

remote ( selenium-hub + selenium node ) chrome example

from qacode.core.bots.bot_base import BotBase
from qacode.core.webs.controls.control_base import ControlBase
SETTINGS = {
    "bot": {
        "log_output_file": "./",
        "log_name": "selenium-issue6217",
        "log_level": "DEBUG",
        "mode": "remote",
        "browser": "chrome",
        "options": {"headless": False},
        "url_hub": "http://localhost:11000/wd/hub",
        "drivers_path": "../qadrivers/",
        "drivers_names": []
    }
}
bot = None
try:
    bot = BotBase(**SETTINGS)
    import pdb; pdb.set_trace() # TODO, remove DEBUG lane
    # TEST
    #nc = bot.curr_driver.get_network_conditions()
    bot.curr_driver.set_network_conditions(latency=5, throughput=5000)
    # END
    import pdb; pdb.set_trace() # TODO, remove DEBUG lane
    #print(nc)
except Exception as err:
    print("ERROR: {}".format(err))
finally:
    bot.close()
  • remote chrome log
(qacode) D:\4.developmentWorkSpaces\1.GITHUB\qalab\modules\qacode>python delete_me.py
2018-07-29 15:03:06,888 - selenium-issue6217 - DEBUG - Starting browser with mode : REMOTE ...
2018-07-29 15:03:10,939 - selenium-issue6217 - INFO - Started browser with mode : REMOTE OK
> d:\4.developmentworkspaces\1.github\qalab\modules\qacode\delete_me.py(22)<module>()
-> bot.curr_driver.set_network_conditions(latency=5, throughput=5000)
(Pdb) c
ERROR: 'WebDriver' object has no attribute 'set_network_conditions'
2018-07-29 15:03:18,113 - selenium-issue6217 - DEBUG - Closing browser...
2018-07-29 15:03:18,151 - selenium-issue6217 - INFO - Closed browser

Expect will be usefull for all :)

for examples im using my own selenium wrapper for python

@netzulo,
Your example code is not helpful. If you have an issue with Selenium, please post selenium related code.

ok. ill keep up in my mind for the next... you have reason, can be confuse :/ right right , ty @cgoldberg

you want to me delete comment ?

This workaround works for me:

# monkey patch: add network conditions support to Remote WebDriver
from selenium import webdriver
remote = webdriver.Remote(...)

from selenium.webdriver.chrome.remote_connection import ChromeRemoteConnection
remote.command_executor = ChromeRemoteConnection(remote.command_executor._url)

import types
remote.set_network_conditions = types.MethodType(webdriver.Chrome.set_network_conditions, remote)
remote.get_network_conditions = types.MethodType(webdriver.Chrome.get_network_conditions, remote)

We currently only support vendor-specific endpoints in vendor-specific webdriver classes, as is the same with the other language bindings. This may change in the future, but for now that is the implementation.

Was this page helpful?
0 / 5 - 0 ratings