logo
down
shadow

Set user-agent with selenium-webdriver and phantomjs in nodejs


Set user-agent with selenium-webdriver and phantomjs in nodejs

By : Dar
Date : November 22 2020, 10:40 AM
wish of those help I need to change the User-Agent of my PhantomJS browser that's driving selenium-webdriver.
code :
    var driver = new webdriver.Builder()
       .withCapabilities(webdriver.Capabilities.phantomjs()
       .set("phantomjs.page.settings.userAgent", useragent))
       .build();


Share : facebook icon twitter icon
Pass the user-agent through webdriver in Selenium

Pass the user-agent through webdriver in Selenium


By : user3818400
Date : March 29 2020, 07:55 AM
With these it helps Changing the user agent in the python version of webdriver is done by altering your browser's profile. I have only done this for webdriver.Firefox() by passing a profile parameter. You need to do the following:
code :
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override","your_user_agent_string")
driver=webdriver.Firefox(profile)
How to change selenium user agent in selenium-webdriver nodejs land?

How to change selenium user agent in selenium-webdriver nodejs land?


By : Femshow
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You cannot do it with Firefox, but you can do it with Chrome. It's undocumented:
code :
var chrome = require('selenium-webdriver/chrome');

var opts = new chrome.Options();
opts.addArguments(['user-agent="YOUR_USER_AGENT"']);

var driver = new webdriver.Builder().
    withCapabilities(opts.toCapabilities()).
    build();
Setting custom User Agent in Selenium Webdriver for PhantomJS with Ruby

Setting custom User Agent in Selenium Webdriver for PhantomJS with Ruby


By : flowbywind
Date : March 29 2020, 07:55 AM
wish help you to fix your issue This ended up not being "possible" out-of-the-box, as moonfly mentioned in his comments to my question. However, this turns out to be relatively easy to do. I should note, that this did not solve my particular problem. I assumed, perhaps naively, that I was getting strange results because of the User-Agent 'Ruby'. Turns out I spent hours figuring this out for nothing; I still get the same result.
But, for those of you that this will help, you'll have to make a quick monkey-patch to Selenium. Nasty, gross, ugly, hacky, I know. But, it did the trick.
code :
module Selenium
    module WebDriver
        module Remote
            module Http

                class Default < Common
                    private

                    def request(verb, url, headers, payload, redirects = 0)
            # THIS IS WHERE OUR CUSTOM CHANGE BEGINS
            headers.merge!('User-Agent' => 'Whatever User Agent You May Want')
            # THIS IS WHERE OUR CUSTOM CHANGE ENDS

            request = new_request_for(verb, url, headers, payload)

            retries = 0
            begin
              response = response_for(request)
            rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EADDRINUSE
              # a retry is sometimes needed on Windows XP where we may quickly
              # run out of ephemeral ports
              #
              # A more robust solution is bumping the MaxUserPort setting
              # as described here:
              #
              # http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx
              raise if retries >= MAX_RETRIES

              request = new_request_for(verb, url, headers, payload)
              retries += 1

              retry
            rescue Errno::ECONNREFUSED => ex
              if use_proxy?
                raise ex.class, "using proxy: #{proxy.http}"
              else
                raise
              end
            end

            if response.kind_of? Net::HTTPRedirection
              raise Error::WebDriverError, "too many redirects" if redirects >= MAX_REDIRECTS
              request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)
            else
              create_response response.code, response.body, response.content_type
            end
          end

        end

      end
    end
  end
end
PhantomJS + Selenium , How to se user agent for links that open in new window?

PhantomJS + Selenium , How to se user agent for links that open in new window?


By : Marcio Golf
Date : March 29 2020, 07:55 AM
Proxy+Selenium+PhantomJS can't change User-Agent

Proxy+Selenium+PhantomJS can't change User-Agent


By : jesus armando macias
Date : March 29 2020, 07:55 AM
it helps some times This is what worked for me:
In my case I took a closer look at the capabilities of the PhantomJS driver:
code :
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 (KHTML, like Gecko) Chrome/15.0.87"

service_args = [
    '--proxy=5.135.176.41:3123',
    '--proxy-type=http',
]
phantom = webdriver.PhantomJS(js_path, desired_capabilities=dcap, service_args =service_args)
print(phantom.capabilities)
{'databaseEnabled': False, 'handlesAlerts': False, 'rotatable': False, 'browserConnectionEnabled': False, 'browserName': 'phantomjs', 'takesScreenshot': True, 'nativeEvents': True, 'locationContextEnabled': False, 'phantomjs.page.settings.userAgent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 (KHTML, like Gecko) Chrome/15.0.87', 'platform': 'linux-unknown-64bit', 'version': '2.1.1', 'applicationCacheEnabled': False, 'driverName': 'ghostdriver', 'webStorageEnabled': False, 'javascriptEnabled': True, 'cssSelectorsEnabled': True, 'proxy': {'proxyType': 'direct'}, 'acceptSslCerts': False, 'driverVersion': '1.2.0'}
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 (KHTML, like Gecko) Chrome/15.0.87"

phantom = webdriver.PhantomJS(js_path, desired_capabilities=dcap)

phantom.capabilities["acceptSslCerts"] = True
phantom.capabilities["proxy"] = {"proxy": "5.135.176.41:3123",
                                 "proxy-type": "http"}
max_wait = 20

phantom.set_window_size(1024, 768)
phantom.set_page_load_timeout(max_wait)
phantom.set_script_timeout(max_wait)
phantom.get(url)
Related Posts Related Posts :
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • Is global variable assignment atomic on NodeJS?
  • Datepicker onchangemonthyear beforeshowday
  • trying to render html files using jade but it still adresses it as a jade
  • Google Analytics - Understanding and Dissecting the Snippet: What is | | [ ];
  • Replacing "[aA09.b]." to "[aA09.b]\n" in in JavaScript
  • Why wrap a function definition in an immediate function?
  • Enable / disable jQuery script on switching to different tab in a HTML page
  • how can find return variable value outside anonymous function in node js mysql query function
  • Converting 1 to 0001 in javascript array
  • svg viewbox should not resize the text fontSize?
  • store newline character with string in a variable
  • MP4 videos in Flowplayer does not play in Windows 7 Chrome
  • jquery focusin event not firing
  • How to debug Vue application with google chrome
  • html 5 web app cache download complete javascript alert?
  • Ember.js setupController fired only once
  • How to validate a currency input
  • How to convert my Array of data to key & value pair
  • Statistics circles in CSS
  • So I wanted to make a trig solver in javascript?
  • Showing HighCharts series name on x-axis and in legend
  • In Rails, how can we pass parameters in script?
  • Build Fails: `npm rebuild node-sass --force`
  • Angular Datepicker change dateformat
  • Trying to extract data from between two sets of characters
  • Configuring Jest in WebStorm
  • Uncaught Error: Syntax error, unrecognized expression: tr.ec_portfolio_title,
  • JQuery fading in fading out continuously
  • Unexpected end of input (Line 1) and Undefined Function?
  • How to animate the width of a div slowly with jquery
  • JavaScript + RegEx Complications- Searching Strings Not Containing SubString
  • SignalR - Unable to get property 'client' of undefined or null reference
  • full calendar not displaying when loaded (with backbone)
  • Angular: Update service and share data between controllers
  • ReplaceAll Google script
  • Search for matching LI items in separate UL
  • Access arguments of an... argument
  • Customizing Google custom search jsapi (query strings)
  • React | Can´t load Images > Module not found
  • Dynamically creating buttons in DOJO
  • 404 Not Found in AJAX post call
  • How do I find out, using javascript, what software opened and running my application?
  • Javascript to check the status of wireless connection
  • StarDict support for JavaScript and a Firefox OS App
  • Phonegap event Resume
  • call javascript function on ENTER key press?
  • When is the best time to remove no-js classes from the html tag
  • Recommended email sending languages
  • setInterval not working properly with chrome
  • Does IE create new scope for each script tag?
  • Uncaught SyntaxError: Unexpected token < Underscore and parse issues
  • How to pass captured URL to Email Body in HTML
  • How to structure default nested resources?
  • Store all the keys of a JSON object in a variable
  • Need an efficient way to group the Array of object in javascript
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org