Skip to content

Changing User-Agent #70

Open
Open
@joshua-biz

Description

@joshua-biz

I'm trying to change the User-Agent used with qtwebdriver, but have as of yet been unsuccessful.

From what I've read, this doesn't seem to be part of the selenium spec (See: SeleniumHQ/selenium-google-code-issue-archive#141), however many other webdriver implementations provide their own way of doing this. If this is already an implemented feature, I would appreciate some direction in how it can be changed, and if not I suppose its a feature request.

Chrome

from selenium import webdriver
chrome_opts = webdriver.ChromeOptions()
chrome_opts.add_argument('useragent="<User-Agent here>"')
driver = webdriver.Chrome(options=chrome_opts)

Firefox

from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preferences("general.useragent.override", "<User-Agent here>")
driver = webdriver.Firefox(profile)

Phantom JS

from selenium import webdriver
phantom_opts = webdriver.DesiredCapabilities.PHANTOMJS
phantom_opts['phantomjs.page.settings.userAgent'] = '<User-Agent here>'
driver = webdriver.PhantomJS(desired_capabilities=phantom_opts)

Above are just for some working examples. Not working example I've tried for use with qtwebdriver:

from selenium import webdriver

capabilities = {'browserStartWindow': '*'}

chrome_opts = webdriver.ChromeOptions()
chrome_opts.add_argument('useragent="<User-Agent here>"')

# Connects fine, doesn't change user agent.
driver = webdriver.Remote(
    'http://127.0.0.1:9517', 
    desired_capabilities=capabilities,
    options=chrome_opts
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions