Can't run Firefox instance when adding FirefoxProfile to FirefoxOptions against SeleniumGrid - c#

NOTE - I am running SeleniumGrid 4.1.0 in Hub-Node mode with Hub and Node running on the same machine.
When I try to run Firefox (ver - 94.0.2) instance using following code nothing happens and Hub freezes
var firefoxOptions = new FirefoxOptions
{
PlatformName = "WINDOWS",
Profile = new FirefoxProfile()
};
_driver = new RemoteWebDriver(seleniumGridUri, firefoxOptions);
Where as if I directly use FirefoxDriver, it works. This works fine
var firefoxOptions = new FirefoxOptions
{
PlatformName = "WINDOWS",
Profile = new FirefoxProfile()
};
_driver = new FirefoxDriver(geckoDriverFolderPath, firefoxOptions);
Can someone please help?

Related

Can I control selenium with firefox portable?

I have read a lot of articles related to using selenium and portable firefox. But the code doesn't work with me. Did I do something wrong? I am using firefox portable 67 and Geckodriver v0.24.0.
FirefoxDriverService driverService = FirefoxDriverService.CreateDefaultService(#"D:\C# Project\FirefoxPortal tesst\FirefoxPortal tesst\bin\Debug\", "geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
//var profile = new FirefoxProfileManager().GetProfile("");
options.Profile = new FirefoxProfile(#"D:\C# Project\FirefoxPortal tesst\FirefoxPortal tesst\bin\Debug\FirefoxPortable\Data\profile");
options.BrowserExecutableLocation = #"D:\C# Project\FirefoxPortal tesst\FirefoxPortal tesst\bin\Debug\FirefoxPortable\FirefoxPortable.exe";
IWebDriver driver = new FirefoxDriver(driverService, options);
driver.Navigate().GoToUrl("https://stackoverflow.com/");
I do not have time today but try changing
options.BrowserExecutableLocation = #"D:\C# Project\FirefoxPortal tesst\FirefoxPortal tesst\bin\Debug\FirefoxPortable\FirefoxPortable.exe";
to
options.BrowserExecutableLocation = #"D:\C# Project\FirefoxPortal tesst\FirefoxPortal tesst\bin\Debug\FirefoxPortable\App\firefox64\firefox.exe";
or to wherever you have your firefox.exe file.

Why does using excludeSwitches in c#

Python code works:
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
But the C# code is not working:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("excludeSwitches", "disable-popup-blocking");
List<string> ls = new List<string>();
ls.Add("enable-automation");
ChromeOptions options = new ChromeOptions();
options.AddExcludedArguments(ls);
using (IWebDriver driver = new ChromeDriver("C:\\Program\\chromedriver", options))
{
Console.ReadKey();
}
I use "excludeSwitches" to get rid of the error showing on the output console.
A device attached to the system is not functioning error using ChromeDriver Selenium on Windows OS
This is my code:
var options = new ChromeOptions();
List<string> ls = new List<string>();
ls.Add("enable-automation");
ls.Add("excludeSwitches");
ls.Add("enable-logging");
ls.Add("disable-popup-blocking");
options.AddExcludedArguments(ls); //set option element in list to options
IWebDriver driver = new ChromeDriver(options); //open webdriver with your options

Selenium ChromeDriver how to disable the message:"DevTools on ws

So I am creating a bot with chrome headless browser and it works just fine. I had quite a lot warnings so I disabled them after reasearch with those commands:
ChromeOptions option = new ChromeOptions();
option.AddArgument("--headless");
option.AddArgument("--silent");
option.AddArgument("--disable-gpu");
option.AddArgument("--log-level=3");
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.SuppressInitialDiagnosticInformation = true;
_driver = new ChromeDriver(service, option);
But there is one more message showing when programs starts:
DevTools listening on ws://127.0.0.1:12015/devtools/browser/6b70a3c5-56c8-4c90-952a-d0e0ef254ddf
Any idea how to disable it from showing?
If you are trying to fix Selenium with Python on Windows, type:
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('headless')
options.add_experimental_option('excludeSwitches', ['enable-logging'])
browser = webdriver.Chrome(options=options)
with the experimental_option line being the special sauce.
That did the trick
var service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
Driver = new ChromeDriver(service, options);
Add following two options .
option.AddArgument("--disable-extensions");
option.AddArgument("test-type");

Selenium.WebDriver with portable FireFox c#

I need to start Selenium with Firefox Portable.
If I start Firefox.exe portable with doublé clic, it starts.
The path to Firefox.exe is correct: A FireFoxPortable folder inside Debug project's folder.
This is the code I use:
var driverService = FirefoxDriverService.CreateDefaultService();
driverService.FirefoxBinaryPath =
Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"FireFoxPortable",
"FireFox.exe");
driverService.HideCommandPromptWindow = true;
driverService.SuppressInitialDiagnosticInformation = true;
var options = new FirefoxOptions();
var driver = new FirefoxDriver(options);
Creating the driver I have an exception -> Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed. OS appears to be: Vista
I try this variant, but no work:
var driver = new FirefoxDriver(driverService);
I'm using this nuget packages:
Is this the correct way?
Thanks for your time!
UPDATE ---------------------------------------------
With this code Works:
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"FireFoxPortable", "FireFox.exe");
FirefoxProfile profile = new FirefoxProfile();
var driver = new FirefoxDriver(new FirefoxBinary(path),profile);
But a Warning for new FirefoxDriver Shown: FirefoxDriver should not be constructed with a FirefoxBinary object. Use FirefoxOptions instead. This constructor will be removed in a future release.'
What's the correct way?

Selenium C# - Loading a profile throws exception in Firefox 48

I am using gecko/marionette driver and have tried both selenium 2 and selenium 3.
I've successfully started a Firefox session with the web driver and without a profile using both options and services to specify a binary:
FirefoxOptions options = new FirefoxOptions();
options.BrowserExecutableLocation = #"C:\Program Files (x86)\Mozilla\Firefox\firefox.exe";
driver = new FirefoxDriver(options);
or
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
driver = new FirefoxDriver(service);
However, when I try to load a profile into it by adding options:
options.Profile = profile;
it gives a corrupt deflate stream exceptionn.
This also occurs when I manually specify the binary file and then try to load the profile (which is deprecated in version 3)
This same profile grab and loading was working prior to the new Firefox update. Is there anything special that needs to be done to get this working?
I've encountered the same problem corrupt deflate stream when loading custom profile, and here is what helped me:
I opened the folder of my custom profile %AppData%\Mozilla\Firefox\Profiles\TestProfile and deleted all empty (0 kB size) files. (they were "AlternateServices.txt" and "parent.lock" in the root of profile directory)
After that the following code worked like a charm:
var FirefoxProfileManager = new FirefoxProfileManager();
var profile = FirefoxProfileManager.GetProfile("TestProfile");
//driver = new FirefoxDriver(profile);
var firefoxService = FirefoxDriverService.CreateDefaultService();
var options = new FirefoxOptions();
options.Profile = profile;
driver = new FirefoxDriver(firefoxService, options, new TimeSpan(0, 0, 30));
The below works for me when using the default profile, I have used this to solve an issue where-by its not using a root cert that we need to get through our security system:
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"C:\\TestData\Dependencies", "geckodriver.exe");
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
FirefoxProfileManager profileM = new FirefoxProfileManager();
FirefoxProfile profile = profileM.GetProfile("default");
//service.Port = 64444;
FirefoxOptions options = new FirefoxOptions();
options.Profile = profile;
Instance = new FirefoxDriver(service,options, TimeSpan.FromMinutes(1));
TurnOnWait();
HTH

Categories