FirefoxOptions AddArgument(s) C# remove throw Exception
OS: Win 10 64
Selenium Version: 3.8.0, WebDriver, C#, GeckoDriver Browser: Firefox
Visual Studio 2017 Pro
npm installed in project: Selenium.Support Selenium.WebDriver Selenium.WebDriver.ChromeDriver Selenium.WebDriver.GeckoDriver.Win64 Selenium.WebDriver.IEDriver Selenium.WebDriverBackedSelenium
Browser Version: Name: Firefox Version.: 57.0.3 Build-ID: 20171226083017 (64-bit) User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0
Expected Behavior -
AddArgument(s) should add command line arguments for starting firefox
Actual Behavior -
AddArgument(s) will throw "All arguments must start with two dashes ('--')"
Steps to reproduce -
AddArguments("-profile","your_path_to_profile");
This would be correct usage for creating a firefox instance with arguments after documentation on https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options Selenium will not allow you to do it correctly and throw the stated error. The error is coded in FirefoxOptions.cs . In JAVA version of Webdriver this is not coded or thrown, i guess the error should be removed in cs code. Line 186-192 in https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/webdriver/Firefox/FirefoxOptions.cs
I don't get the sense of throwing this error as it will prevent correct usage.
Absolutely useless, prevents the proper usage please update. See #5290
@HthSolid I left for an extended holiday on 7 January 2018, and am just now returning to work on Selenium tasks. Additionally, Selenium isn’t my top priority since returning. Nevertheless, thanks for the report; I’ll see about trying to get this updated soon.
As for the cause, at one time, the requirement for use with geckodriver was that Firefox arguments were required to be preceded by two dashes. That requirement has changed to be a single dash, and the .NET bindings haven’t kept up. As for the differences between Java and .NET, that’s a slight difference in philosophy of the bindings. When there are known requirements for input, rather than accepting anything, sending it down the wire, and letting the remote component send back an error, the .NET bindings seek to prevent the incorrect input in the first place. While I believe that ultimately allows for better control of what the user experiences, it does incur a cost in maintenance that sometimes leads to disconnects like this.
@jimevans Thank you for your reply. I would suggest to remove the requirement of dashes completely as the geckodriver uses the second part of an argument very often without any dashes.
@HthSolid There’s a disconnect on what constitutes an “argument.” For example, consider adding a profile, which would need the following added to the command line:
-profile path-to-profile
As you say, some might be tempted to see this as two arguments, in which case, yes, the requirement for a leading dash would be problematic. Others could argue that it’s a single argument (e.g., options.AddArgument(“-profile path-to-profile”), and should be treated as such. I think it’s a mistake to not prevalidate the input before sending it down the wire. However, given the changes to geckodriver support the former interpretation rather than the latter, that’s probably the change that will be made.
@jimevans I agree it should be seen as one, but seen the usage from gecko as stated in cmd-line-pic from #5290 I see that gecko itself uses profile with path as two argument, which would mean options.AddArgument(“-profile path-to-profile”) should not work, otherwise please prove me wrong.
@HthSolid I apologize for being unclear. The removal of restrictions on arguments altogether is “the change that will be made.”
Fixed in commit c2a11e6