As per title, I have a Remote selenium driver (with Chrome capabilities), and I need to change its user agent without creating another driver.
My remote driver is set like this:
from selenium.webdriver import Chrome, Remote
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
url = "http://selenium-hub:4444/wd/hub"
driver = Remote(url, desired_capabilities=DesiredCapabilities.CHROME)
I know already that the standard way is to create Chrome Options, and add user-agent argument like this:
options = Options()
options.add_argument(f"user-agent={my_user_agent}")
driver = Chrome(options=options)
# also working for remote
# driver = Remote(url, desired_capabilities=DesiredCapabilities.CHROME, options=options)
But, as said before, I need to change the user-agent within the same driver without creating another one.
I also found this thread and, from it, the function execute_cdp_cmd
, but it's only working for Chrome, not for Remote.
Is there a way to run this instruction on a Remote driver? Or another way to set a user-agent "dynamically"?
Thank you in advance