I use Selenium WebDriver in my C# winforms application. When I run application and open Firefox, my addons are disabled. How to leave the addons enabled?
You can explicitly set the desired addons to ON. For example, if you want to enable firebug, find out the location of the zip or xpi of the addon and then use the following code:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.AddExtension("C:\\firebug.xpi");
ffprofile.SetPreference("extensions.firebug.currentVersion", "1.11.4");
IWebDriver driver = new FirefoxDriver(ffprofile);
The only thing I did to resolve is just by adding following to the pom.xml and it worked fine for me. Currently I'm running tests on Firefox 43.0.3 with Selenium 2.48.2. and also by have a dependency for the Firefox browser in the pom.xml.
org.seleniumhq.selenium selenium-firefox-driver 2.48.2
org.seleniumhq.selenium selenium-java 2.48.2
After using this if you fail to use your add on than drop message I will provide you some more options but hope fully you will get result from this.
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.
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 using the new Gecko Driver to test in Firefox. When I change the url it often fails. I have a test that goes to 10 different pages to perform a very basic health check. The pages always load when using Firefox manually (not Gecko/Selenium), but when using the Gecko driver it fails on the GoToUrl().
It's not consistent which of the ten pages it fails on, but it is always consistently failing on one of the ten. When it fails Firefox closes and an error message pops up asking if I want to submit the details to Mozilla.
Am I doing something wrong, or is there some restriction with the Gecko driver that I am unaware of? The Chrome and internet explorer drivers handle the exact same test just fine.
var service = FirefoxDriverService.CreateDefaultService(DriverPathOnSystem);
var driver = new FirefoxDriver(service);
driver.Navigate().GoToUrl(url);
EDIT
Selenium.Support v3.4.0 (nuget)
Selenium.WebDriver v3.4.0 (nuget)
Firefox 51.0.1 (32-bit) but also using the most recent version on the
build machine and it has the same failure there
Gecko 0.16.0
Upon further research I discovered I was actually using WebDriver v3.2.0.
I updated WebDriver to v3.4.0,
updated FireFox to 53.0.0,
updated GeckoDriver to 0.16.1
cleaned the solution and rebuilt and it worked.
Could anyone suggest headless browser for .NET that supports cookies and authomatically javascript execution?
Selenium+HtmlUnitDriver/GhostDriver is exactly what you are looking for. Oversimplified, Selenium is library for using variety of browsers for automation purposes - testing, scraping, task automation.
There are different WebDriver classes with which you can operate an actual browser. HtmlUnitDriver is a headless one. GhostDriver is a WebDriver for PhantomJS, so you can write C# while actually PhantomJS will do the heavy lifting.
Code snippet from Selenium docs for Firefox, but code with GhostDriver (PhantomJS) or HtmlUnitDriver is almost identical.
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
class GoogleSuggest
{
static void Main(string[] args)
{
// driver initialization varies across different drivers
// but they all support parameter-less constructors
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com/");
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Cheese");
query.Submit();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
System.Console.WriteLine("Page title is: " + driver.Title);
driver.Quit();
}
}
If you run this on Windows machine you can use actual Firefox/Chrome driver because it will open an actual browser window which will operate as programmed in your C#. HtmlUnitDriver is the most lightweight and fast.
I have successfully ran Selenium for C# (FirefoxDriver) on Linux using Mono. I suppose HtmlUnitDriver will also work as fine as the others, so if you require speed - I suggest you go for Mono (you can develop, test and compile with Visual Studio on Windows, no problem) + Selenium HtmlUnitDriver running on Linux host without desktop.
I am not aware of a .NET based headless browser but there is always PhantomJS which is C/C++ and it works fairly well for assisting in unit testing of JS with QUnit.
There is also another relevant question here which might help you - Headless browser for C# (.NET)?
I am using Selenium RC using c# and need to take screenshot for the test case failed, I have to perform these test on IE 8.
I got lot of tutorials for Firefox but didn't find any for the IE8.
Thanks in advance.
You can use the Selenium Web Driver to take a screenshot of IE pretty easily. The code would look something like this:
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.com");
TakeScreenshot(driver, #"C:\screenshot.png");
You can download the Web Driver here: https://code.google.com/p/selenium/downloads/list
Add it to your project and you are off and running.