1

I am pretty new to C# and integrating with firefox.

So this might be a very basic newbie question :)

I have this code:

using OpenQA.Selenium;

using OpenQA.Selenium.Firefox;

using OpenQA.Selenium.Support.UI;

FirefoxOptions options = new FirefoxOptions();

options.SetPreference("browser.download.folderList", 2);

options.SetPreference("browser.download.dir", "C:\\Windows\\download");
options.SetPreference("browser.download.useDownloadDir", true);
options.SetPreference("browser.helperApps.neverAsk.saveToDisk", "text/xml");   
options.SetPreference("pdfjs.disabled", true);  // disable the built-in PDF viewer

WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.mozilla.org/en-US/foundation/documents");
driver.findElement(By.linkText("IRS Form 872-C")).click();

The WebDriver is marked with red. It is not recognized.

I have following installed :

enter image description here

enter image description here

enter image description here

What am I missing?

imxitiz
  • 3,920
  • 3
  • 9
  • 33
  • I tried to search 'WebDriver' on .Net API Browser but found nothing. Maybe you miss some NuGet package? – ZelgiusLiu Jun 15 '20 at 09:53
  • I belive I have the required NuGet packages see images above. Maybe I need a namespace? – KeepDevelopingDK Jun 16 '20 at 08:10
  • Well, it is not an instance for `WebDriver`, there seems not such a class. That should be an instance of `IWebDriver` interface. Then the code should be `IWebDriver driver = new FirefoxDriver(option)`. – ZelgiusLiu Jun 16 '20 at 08:49
  • 'IWebDriver' does not contain a definition for 'get' and no accessible extension method 'get' accepting a first argument of type 'IWebDriver' could be found (are you missing a using directive or an assembly reference?) – KeepDevelopingDK Jun 16 '20 at 12:05
  • 'IWebDriver' does not contain a definition for 'findElement' and no accessible extension method 'findElement' accepting a first argument of type 'IWebDriver' could be found (are you missing a using directive or an assembly reference?) – KeepDevelopingDK Jun 16 '20 at 12:06
  • Then I get the above errors :( – KeepDevelopingDK Jun 16 '20 at 12:06
  • The last line could be `driver.FindElement(By.LinkText("IRS Form 872-C")).Click();`. But as for the `Get` method, I found nothing. There are some methods start with 'Get', but none of them allows string param. I wonder where did you get this code, it is unusual in C# that you declare a method with a name start with lowwer case, especially in some large open source project. – ZelgiusLiu Jun 16 '20 at 14:38
  • I got a lot of the code from here: – KeepDevelopingDK Jun 18 '20 at 06:40
  • https://stackoverflow.com/questions/51949871/selenium-download-file-automatically-c-sharp The accepted answer use: WebDriver driver = new FirefoxDriver(options); in link. – KeepDevelopingDK Jun 18 '20 at 06:41
  • Seems you got the code fro the second answer. But read it carefully, the provider said he did it in Java, so that code is likely used in Java, as well as the first answer. Looking at the last line of code in question `driver.FindElement(By.LinkText("IRS Form 872-C")).Click();`, it is the usage in C#. Usually, C# recommend declaring a method with name start with upper case. – ZelgiusLiu Jun 18 '20 at 09:08
  • Okay that could be a good explanation. I think I give up it is not crucial. – KeepDevelopingDK Jun 19 '20 at 10:11

0 Answers0