When I create a firefox driver with a firefox driver service this is logged to the console: 1564067211938 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\minec\\AppData\\Local\\Temp\\rust_mozprofile.wCNOb94oHRE2" The problem is the console when this happens gets effectively separated from my program and doesn't close when I close it with the stop button in visual studio. I also can't log anything to the console after that.
Is there any way to disable it?
Here is my code:
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(geckoDriverPath.Replace(#"\geckodriver.exe", ""), "geckodriver.exe");
var driver = new FirefoxDriver(service);
I figured out how to remove all logs except fatal error logs.
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(geckoDriverPath.Replace(#"\geckodriver.exe", ""), "geckodriver.exe");
var options = new FirefoxOptions();
options.LogLevel = FirefoxDriverLogLevel.Fatal;
var driver = new FirefoxDriver(service, options);
Try adding System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "target" + File.separator + "browser.log");
before the browser is being initialized
ie. before
var driver = new FirefoxDriver(service);
Related
Hi. I tried upgrade my chromedriver to 101.0.4951.41 today and it sudden keep prompt this error to me. Anything I missed or what I should add for new version?
And this is my code:
options.AddArgument("start-maximized");
options.AddArgument("--disable-extensions");
options.AddArgument("--disable-blink-features");
options.AddArgument("--disable-blink-features=AutomationControlled");
options.AddArgument("--disable-gpu");
options.AddArgument("--no-sandbox");
options.AddArgument("--allow-running-insecure-content");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--disable-background-networking");
options.AddExcludedArguments(new List<string>() { "enable-automation" });
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("password_manager_enabled", false);
ChromeDriverService chromeDriverService=ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
IWebDriver Driver = new ChromeDriver(chromeDriverService, options);
IDevTools devTools = Driver as IDevTools;
IDevToolsSession session = devTools.GetDevToolsSession();
Fixed by adding the protocol version (i.e.)
using DevTools = OpenQA.Selenium.DevTools.V96;
:
:
IDevTools devTools = webDriver as IDevTools;
IDevToolsSession session = devTools.GetDevToolsSession(96);
Had a similar issue and it seems in versions above and equal 100 need to have the remote-debugging-port argument set.
Add this to args:
"--remote-debugging-port=9222"
This opens the devtools for me when I open the driver itself. I tested it on version 101.0.4951.41 so it should work fine for you. (no remote debugging port required)
options.AddArgument("--auto-open-devtools-for-tabs");
Apparently the new version of chromedriver (101.0.4951.41) is not compatible with old version of DevTools
I can solved this issue updated Selenium.WebDriver to 4.1.1 and used "OpenQA.Selenium.DevTools.V101.Network"
I am using below mentioned code to initialize a firefox driver with service, options and timeout.
var Service = FirefoxDriverService.CreateDefaultService(RunConfig.DriverPath);
Service.HideCommandPromptWindow = RunConfig.HideDriverCommandPromptWindow;
var Options = new FirefoxOptions();
if (!string.IsNullOrWhiteSpace(RunConfig.PathToBrowserBinary))
Options.BrowserExecutableLocation = RunConfig.PathToBrowserBinary;
Options.Profile = new FirefoxProfile();
Options.Profile.SetPreference(Preference.Name,PathToDownloadFolder));
Options.Profile.SetPreference(Preference.Name, Preference.Value);
return new FirefoxDriver(Service, Options, TimeSpan.FromSeconds(90));
But it gives me an error that The path is not of legal for while initializing firefox profile
Solved it. The problem was the seleniumwebdriver dll I was using is present in some other project. Adding the selenium webdriver and support dll to the current project worked.
For the past 2 days, I've been trying to find a way to start Chrome with a different profile but to no avail.
No matter what I do, the profile that Selenium loads for chrome is always some temporary profile like "C:\Users\DARKBO~1\AppData\Local\Temp\scoped_dir14308_25046\Default"
I have tried the following code:
ChromeOptions options = new ChromeOptions();
options.AddArgument(#"user-data-dir=C:\SeleniumProfiles\Default");
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("chrome://version");
First I tried using the directories for the profiles directly from the Chrome folder, didn't work. Then I created a new folder and moved the profiles there, I've tried doing this both in C:\ and in D:\ . No difference whatsoever.
I've tried running the user-data-dir argument both like it currently is in the code and with -- in front of it. I've tried using double backslashes without the # symbol, still nothing. No matter what I do the profile directory is always the Selenium temp directory.
P.S. The current C:\SeleniumProfiles directory I created through the command prompt using the chrome user-data-dir=C:\SeleniumProfiles command
P.S. 2: My mistake was very simple, I forgot to put the options in the constructor of the new driver. And as Tarun made it clear, user-data-dir only gives Chrome the directory that contains the profiles, then we need to use profile-directory argument to give the subdirectory that contains the needed profile.
You din't use the options objects at all.
IWebDriver driver = new ChromeDriver();
Should be
IWebDriver driver = new ChromeDriver(options);
Edit-1 - Chrome profiles and users
Chrome has User data directory for storing profiles. Inside this directory multiple profiles can be maintained. There are two arguments that can be used
user-data-directory
profile-directory
If only user-data-directory is specified then a Default directory inside the same would be used. If profile-directory is specified then that directory inside the user-data-directory is used
If you are starting with the profile of the browser on the computer you are looking for, you can
Open normal google chrome and go to ('chrome://version')
enter link description here
Copy the Profile Path but take all of the "Data" folder and copy it to where the program is running
C# Coding:
https://rextester.com/INK23784
By creating a folder named "profile" where the program is running, you can add all the profile information, plugins, and so on. etc. We have copied the data folder in everything and when opening the browser "ChromeOptions" to selenium your profile files, etc. that's everything
You can try this code: (It worked for me)
string path_profile = #"D:\PROJECT_XMARKETING_4.0\Profiles\1";
// string path_profile = #"D:\PROJECT_XMARKETING_4.0\Profiles2\2";
IWebDriver _webDriver;
ChromeDriverService cService = ChromeDriverService.CreateDefaultService();
cService.HideCommandPromptWindow = true;
_webDriver = new ChromeDriver(cService);
_webDriver.Manage().Cookies.DeleteAllCookies();
ChromeOptions options = new ChromeOptions();
options.AddArgument($"user-data-dir={path_profile}");
_webDriver = new ChromeDriver(cService, options);
//_webDriver.Navigate().GoToUrl("https://phamtani.com/");
//_webDriver.Navigate().GoToUrl("https://alink.vn/");
//_webDriver.Navigate().GoToUrl("http://api.hostip.info/get_json.php");
Set user-data-dir to C:\Users[your-username]\AppData\Local\Google\Chrome\User Data
Full Code:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
private IWebDriver _driver { set; get; }
public YourConstructor()
{
_driver = CreateBrowserDriver();
}
private IWebDriver CreateBrowserDriver()
{
try
{
var options = new ChromeOptions();
options.AddArgument("test-type");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("no-sandbox");
options.AddArgument("disable-infobars");
//options.AddArgument("--headless"); //hide browser
options.AddArgument("--start-maximized");
//options.AddArgument("--window-size=1100,300");
//options.AddUserProfilePreference("profile.default_content_setting_values.images", 2);
// Profile [Change:User name]
options.AddArgument(#"user-data-dir=C:\Users\Haddad\AppData\Local\Google\Chrome\User Data");
var service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
service.SuppressInitialDiagnosticInformation = true;
return new ChromeDriver(service, options);
}
catch
{
throw new Exception("Error: Chrome is not installed.");
}
}
Can someone advise me on how to set the path for the firefox exe file in Selenium (C#).
I'm using the following code presently, however it is not working as hoped:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
IWebDriver driver = new FirefoxDriver(profile);
Any suggestions would be appreciated.
You should use FirefoxBinary instead of FirefoxProfile as below
FirefoxBinary binary = new FirefoxBinary(new File("path/to/binary"));
FirefoxOptions options = new FirefoxOptions();
options.setBinary(binary);
IWebDriver driver = new FirefoxDriver(options);
Another option is to configure the system property.
System.Environment.SetEnvironmentVariable("webdriver.firefox.bin", 'path/to/binary');
I'm using Selenium RC + .Net Client Driver. I've created a Firefox profile in my c:\selenium\ directory. Here's my code:
Dim MySelenium As ISelenium = Nothing
MySelenium = New DefaultSelenium("localhost", 4444, "*custom C:/Program Files/Mozilla Firefox/firefox.exe -profile c:/selenium/", "http://www.google.com/")
When I run this, I get the following error:
Failed to start new browser session: Error while launching browser
What is the proper way to do this?
You need to launch it via RC rather than in your code.
So you would do
java -jar selenium-server.jar -firefoxProfileTemplate c:\selenium\
to launch the browser and then do
Dim MySelenium As ISelenium = Nothing
MySelenium = New DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/")
and that should launch Firefox for with the profile you want.
In Java you can create the Selenium Server programmatically and pass a File as the newFirefoxProfileTemplate configuration property:
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
rcc.setPort(5499);
rcc.setFirefoxProfileTemplate(newFirefoxProfileTemplate); // This is a File object
SeleniumServer server = new SeleniumServer(rcc);
server.start();
Perhaps there are similar (or the same) vb.net classes available.