im writing a automation tool in visual studio with c#.
im using selenium with chromedriver. i need proxy user pass auth for my session. But i try so many times and so many sources but didnt work.
How to basicly user pass ip port proxy for my chromedriver session. Thanks for help.
There are a couple of options.
Configuring a proxy using ChromeOptions and org.openqa.selenium.Proxy
If you want the solution to be easily portable to run on other systems, you can try configuring a proxy using ChromeOptions and org.openqa.selenium.Proxy. There will be some additional methods in here to configure your proxy, but we need to know what type of proxy and type of authentication is supported.
// Add the WebDriver proxy capability.
Proxy proxy = new Proxy();
proxy.setHttpProxy("myhttpproxy:3337");
options.setCapability("proxy", proxy);
// Add a ChromeDriver-specific capability.
ChromeDriver driver = new ChromeDriver(options);
Create a new chrome profile with proxy configuration
Alternatively, you could create a profile for chrome with the proxy configured and tell chrome driver to work with that. This would be difficult, if not impossible, to port to other systems without manual setup, unless you containerized it, but that's out of scope here.
As of chrome 71, head to chrome settings at chrome://settings/ and choose Manage other people. Create a new person to represent your proxy profile. Configure the proxy using the browser the way you normally would for manually connecting.
Locate the path to your profile, something like: C:\Users\<username>\AppData\Local\Google\Chrome\User Data\Profile 1 if you're on windows. You can easily find by navigating to chrome://version/ and looking for Profile Path
Utilize ChromeOptions to pass the option for setting the user data directory for chrome on startup
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
Some snippets pulled from documentation for chromedriver
Related
I want to load a new Selenium ChromeDriver that is using Chrome as if I open Chrome from my dock (Essentially it'll have all my extensions, history, etc.)
When I use the following code:
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data\\");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
It loads the Chrome browser with me signed into my Gmail and with all my extensions, just like I want, but the rest of my code:
chromeDriver.Navigate().GoToUrl("https://www.youtube.com/");
doesn't execute. But when I use the following
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\Andrea\\AppData\\Local\\Google\\Chrome\\User Data\\Default");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
The rest of my code executes perfectly (Notice the 'Default' added to the end of the first Argument). Any tips or suggestions on how I can get the first block of code (The one without 'Default' on the end) to execute the rest of my program would be great. Thanks!
I know this is an old question, but what worked for me is to do remove the "C:\" and replace all of the backslashes with forward slashes. So, with that from the original question, this should work to load the default profile:
options.AddArgument("user-data-dir=/Users/User/AppData/Local/Google/Chrome/User Data");
The Default Chrome Profile which you use for your regular tasks may contain either/all of the following items:
History
Bookmarks
Cookies
Extensions
Themes
Customized Fonts
All these configurations untill and unless are part of your Test Specification it would be a overkill to load them into the session initiated by Selenium WebDriver. Hence it will be a better approach if you create a dedicated New Chrome Profile for your tests and configure it with all the required configuration.
Here you will find a detailed discussion on How to create and open a Chrome Profile
Once you have created the dedicated New Chrome Profile for your tests you can easily invoke the Chrome Profile as follows:
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
chromeDriver.Navigate().GoToUrl("https://www.youtube.com/");
Here you will find a detailed discussion on How to open URL through default Chrome profile using Python Selenium Webdriver
I have the same issue. I don't know how to fix it, I guess the root cause is white space in profile path.
I know a workaround for this. Just copy the C:\\Users\\Andrea\\AppData\\Local\\Google\\Chrome\\User Data to c:\myUserData (no space in the path).
Then add the argument.
options.AddArgument("user-data-dir=C:\\myUserData");
This is an Old question, but if you are facing this issue, all you have to do is close all tabs, Just shut down the chrome window..
Selenium can't use the data since it is already in use.
Hope you fond this helpful.
Is it my understanding that when using Selenium.WebDriver v3.7 from NuGet I require a current version of geckodriver in order to interact with Firefox ESR v52.4.1. However, I have managed to get tests running and successfully passing without geckodriver being involved at all.
I believe it is because I have enabled the legacy implementation option when instantiating the RemoteWebDriver, as illustrated below.
FirefoxOptions options = new FirefoxOptions
{
UseLegacyImplementation = true, // means that geckodriver is not required
BrowserExecutableLocation = ..., // ensures authorised Firefox version used
Profile = ... // an instance of FirefoxProfile
};
RemoteWebDriver remoteWebDriver = new FirefoxDriver(options);
A number of questions to help me understand the details:
Does this mean that Selenium.WebDriver is talking directly to the Firefox browser using the Marionette protocol?
If so, does this setup rely on libraries currently distributed with the NuGet package that might be (will?) be dropped in a forthcoming release?
If so, any idea which release or when that is likely to be?
Thanks!
Does this mean that Selenium.WebDriver is talking directly to the Firefox browser using the Marionette protocol?
As per my understanding, when you set System.setProperty("webdriver.firefox.marionette", "false"); to false or do FirefoxOptions options = new FirefoxOptions()
.setLegacy(true); that means it is using the legacy extension (not marionette and gecko) as described in firefox properties here
Marionette can not be used without using gecko (or rather if you want to interact with gecko based browsers, you have to use marionette ). Marionette has a gecko component in it which is the marionette server as mentioned here
geckodriver as it is written on github , provides an API to communicate with Gecko browsers
This program provides the HTTP API described by the WebDriver protocol
to communicate with Gecko browsers
for selenium 3.0 onwards marionette is enabled by default as mentioned here
For more info please refer to this question also
If you are interested in learning more about marionette client-server-gecko interaction , have a look here
EDIT:
the source code of geckodriver states below points about geckodriver at different locations in readme.md
geckodriver is a Proxy for using W3C WebDriver-compatible clients to interact with
Gecko-based browsers.
Selenium client bindings will pick up the geckodriver binary executable
from your [system’s PATH environmental variable][PATH]
3.Since geckodriver is a separate HTTP server that is a complete
remote end
implementation of [WebDriver], it is possible to avoid using the
Selenium remote server
geckodriver translates WebDriver [commands], [responses],
and [errors] to the [Marionette protocol], and acts as a proxy between
[WebDriver] and [Marionette]
By default geckodriver tries to find
and use the system installation of Firefox
So , to answer your questions, this is how it all works
Selenium language bindings reaches to -->geckodriver.exe finds -->system firefox installation(this can be changed though)reaches to inbuilt --> marionette client reaches to --> marionette server reaches to --> gecko engine of the browser which inturn calls out --> element.js,interaction.js,action.js,evaluate.js in gecko engine depending on what is being requested by the bindings or client.
So, below is my basic code to try out Browsermob Proxy, and the output generated.
The issue is with the output, which appear to be (1) incomplete in number and (2) not as detailed as I would manually check the network statistics in Dev tools (Firefox or Chrome).
Is it possible to have more detailed info in the HAR file? I would like to know, for example, if a specific Javascript has been loaded (or is there a better solution to this?).
// Supply the path to the Browsermob Proxy batch file
Server server = new Server(#"C:\Users\Frederik\Desktop\SeleniumTestje\browsermob-proxy-2.1.0-beta-6\bin\browsermob-proxy.bat");
server.Start();
Client client = server.CreateProxy();
client.NewHar("google");
var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy };
var profile = new FirefoxProfile();
profile.SetProxyPreferences(seleniumProxy);
// Navigate to the page to retrieve performance stats for
IWebDriver driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://www.google.co.uk");
// Get the performance stats
HarResult harData = client.GetHar();
foreach(Entry e in harData.Log.Entries)
{
Console.WriteLine(e.Request.Url, e.Request.Headers);
}
Output in console:
http://ocsp.digicert.com/
http://ocsp.digicert.com/
http://ocsp.digicert.com/
http://www.google.co.uk/
http://clients1.google.com/ocsp
http://clients1.google.com/ocsp
http://clients1.google.com/ocsp
http://clients1.google.com/ocsp
I had the same issue with Fiddlercore but I have found a solution for that:
Fiddlercore - Requested resource URL's are generic (OSCP-related) instead of actual resource
I ran into this issue as well. It ended up being Chrome's networking tools enables its own cache by default, so BrowserMobProxy is not aware of all of the requests.
To fix the automated .har so that it is identical to a manual one, select the Disable Cache checkbox in the network tools. More info here: Disabling Chrome cache for website development
for the past two days I've been trying to use a proxy with Selenium, that's not exactly the issue though. The issue is that the proxy is private meaning it needs authentication to use it (Username and Password) but I can't figure out how to do it.
I'm using a Firefox driver, with a profile like so:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("network.proxy.type", 1);
firefoxProfile.SetPreference("network.proxy.http", "23.95.115.87");
firefoxProfile.SetPreference("network.proxy.http_port", 80);
var driver = new FirefoxDriver(firefoxProfile);
driver.Navigate().GoToUrl("http://ipchicken.com");
I figured that it would ask me for the username and password (in a dialog box) yet nothing happens, it just navigates to the webpage, and displays my own IP. I can't find anything really on this, any help guys? Thank you so much.
I am not an expert in Selenium but I can help you in making your proxy authentication free.
If you are on Windows, download something like CC-Proxy ( Its free for a single user) and add your proxy as a cascading proxy. This will create a local proxy server on your computer which won't require username/password. Then you can use the local proxy server in selenium.
If you are on Linux, you can use wine to run CC-Proxy or you can use tinyproxy or squid ( it is an overkill).
Comment if you face problem in setting up CC-Proxy or tinyproxy.
I am testing a website using selenium web driver. The particular site contains nested iframes. I cannot access content of Iframes, because of the Same Origin Policy. Therefore I disabled web security in chrome web driver and access those contents using following Jquery script.
$(‘#data’).find(‘iframe’).contents().find(‘html’)
I achieved this in chrome by setting these features when it is initializing.
ChromeOptions options = new ChromeOptions();
options.AddArguments("--allow-file-access-from-files");
options.AddArguments("--disable-web-security");
IWebDriver driver = new ChromeDriver(options);
(Domain of iframes are differ with my hosted domain.)
Now I need to do this in Firefox. I followed instructions in this URL. But that is not working.
about:config -> security.fileuri.strict_origin_policy -> false
Then I tried with these edits
about:config -> security.mixed_content.block_active_content -> false
about:config -> security.mixed_content.block_display_content -> false
Then I loaded Firefox profile and init web driver using that.
FirefoxProfile profile = new FirefoxProfile(#"C:\Users\admin\AppData\Roaming\Mozilla\Firefox\Profiles\0nan0gbv.default");
IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver(profile);
I haven't got what I expected using above edits. Error was Permission denied to access property 'document'
Then I tried set these settings into new Firefox profile(not use default one in my machine) and load it.
OpenQA.Selenium.Firefox.FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("browser.privatebrowsing.autostart", true);
profile.SetPreference("security.fileuri.strict_origin_policy", false);
profile.SetPreference("security.mixed_content.block_active_content", false);
profile.SetPreference("security.mixed_content.block_display_content", true);
IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver(profile);
Then I got this error and couldn't able to find proper solution.
Preference security.fileuri.strict_origin_policy may not be overridden: frozen value=False, requested value=False
I found this question has many ways to overcome SOP. But those are not answers for my problem.
There should be way to achieve this. I am using Firefox 29.0.1