cisco-open-source / qtwebdriver

WebDriver implementation for Qt
https://github.com/cisco-open-source/qtwebdriver/wiki
198 stars 59 forks source link

Changing User-Agent #70

Open joshua-biz opened 5 years ago

joshua-biz commented 5 years ago

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: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/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
)