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
Related
Browsing with chrome to web site with htpps connection manually is available and display the site.
Browsing same site by selenium automated test, doesn't display the page, display empty page.
If i load chrome user profile, automation do open the required page.
Other https site (QA) does displayed through automated connection, the problem is with production sites.
Is there any setting can be added to selenium to open the page?
try this if works
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--start-maximized");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("disable-infobars");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
UnexpectedAlertBehaviour.ACCEPT);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver.set(new ChromeDriver(cap));
After the issue solved, posting here the solution.
The site wasn't displayed because automation requests were blocked by company WAF (firewall).
The solution on the automation side was to add agent into chrome profile options and on the waf side rule was added for the agent that allows access to the application.
This is example of how the agent added into ChromeOptions class:
ChromeOptions options = new ChromeOptions();
options.AddArgument("--user-agent=automation-client");
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
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.
I am using Selenium and Firefox for automated testing, and I need the files to download automatically. Here are two links that I've used to setup my code.
Auto download PDF in Firefox
Set Firefox profile to download files automatically using Selenium and Java
To summarize the articles, the code should look like this:
FirefoxOptions options = new FirefoxOptions();
options.setPreference("browser.download.folderList", 2);
options.setPreference("browser.download.dir", "C:\\Windows\\temp");
options.setPreference("browser.download.useDownloadDir", true);
options.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
options.setPreference("pdfjs.disabled", true); // disable the built-in PDF viewer
WebDriver driver = new FirefoxDriver(options);
When I run my test, the auto-download fails. I checked in the about:config and the settings have been changed as intended by the code.
(about:config screenshot)
Also, within that driver instance, if I change any setting and then reapply the same setting, the auto-download works. Is there a setting or step with the webdriver that I'm missing that then applies the new settings?
Here are the Selenium, Firefox, and GeckoDriver versions I've tested with:
Selenium: v3.12.0
Firefox: 59.0.3, 60.0.1
GeckoDriver: v0.19.0-win64, v0.20.0-win64, v0.21.0-win64
As far as i know is pretty difficult download files with selenium because the browser open some dialogs that is not possible control from javascript. Watch this link, I hope will be useful
I am running chromedriver on windows server 2016 with IIS, i have my test project installed and invoking it with an MVC5 API. That all seems fine but chromedriver and chrome.exe only seems to open as a background processes.
The same code opens these fine locally, i am not using any of the driver flags for headless browsing either. if i return the drive page source i can see that chromedriver went to google and returned the correct html in my API.
It just does not work for normal / non headless tests with google or our application.
var driver = x.StartWebDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://www.google.com");
return driver.PageSource;
Any ideas?
I have got the same issue and this is how I solve this:
Open a command prompt and navigate to your ChromeDriver location.
Execute chromedriver.exe and you will see the message as below.
image here
In the image above you see chrome driver is listening on port 9515.
Now change your code as below, rebuild and call you api to execute your test.
ChromeOptions options = new ChromeOptions();
//set your chromeoptions here
Uri uri = new Uri("http://localhost:**9515");
_driver = new RemoteWebDriver(uri, options);
Open the chrome driver and note the port number(eg:5353)
In java:
System.setProperty(chromeDriverName, chromeDriverLocation);
ChromeOptions options = new ChromeOptions();
URL uri = new URL(chromeDriverPort);//http://localhost:5353
WebDriver driver = new RemoteWebDriver(uri, options);
your problem gets solved in is server.