Answer the question
In order to leave comments, you need to log in
How to change User Agent in Selenium WebDriver using ExecuteScript?
Good afternoon, the task is to change the User Agent (information about the browser, OS, etc., in the already running Selenium test on the fly, automatically, through the code, and not manually)
I write in PowerShell, but in Python the essence is the same:
add-type -path "C:\Program Files\WindowsPowerShell\Modules\Selenium\1.1\assemblies\WebDriver.dll"
$options = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 11.12; rv:68.0) Gecko/20100101 Firefox/67.0"
$options.addArguments("user-agent=$UserAgent");
$driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($options)
$Driver.Navigate().GoToUrl("https://2ip.ru/")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question