none
C# won't let me "see" an object in the project RRS feed

  • Question

  • 		public static Page mtWizardsMenu = new Page("Wizards", MainMenu.MainMenuPage.MainMenuIcons.wizardsIcon, mtMainMenu);
    
    		public static Page mtDeviceSettings = new Page("Device Settings", Settings.SettingsPage.deviceSettingsText, mtSettingsMenu);

    C# is happy with the first line of code referencing MainMenu.MainMenuPage.MainMenuIcons.wizardsIcon, but not the second line where it references Settings.SettingsPage.deviceSettingsText, saying "The name Settings does not exist in the current context."

    I tried putting "using Settings;" but it's not happy with that either.

    "Settings" is a name space with a class in SettingsPages.cs:

    using System;
    using OpenQA.Selenium;
    
    namespace Settings
    {
      public class SettingsPage
      {
     
    
        //!Locators for the the new sub element menus
        public static readonly By deviceSettings = By.Id("deviceSettings");
        public static readonly By deviceSettingsText = By.XPath("//*[@id='deviceSettingsSubElement'][contains(text(),'Device Settings')]");
        public static readonly By deviceSettingsValue = By.Id("deviceSettings_SubElementValue");
    
    bla bla bla
       }
    }


    This looks to me like the MainMenu namespace in MainMenuPages.cs:

    using System;
    using OpenQA.Selenium;
    
    namespace MainMenu
    {
      public class MainMenuPage
      {
        //The Main Menu Page class models the functionality on the Main Menu HTML page. The class stores the elements of interest (state) in variables and any actions that can be performed with those elements (behavior) in methods.
    
        public class MainMenuIcons
        {
          bla bla bla
          public static readonly By informationIcon = By.Id("informationMenuItem");
          public static readonly By wizardsIcon = By.Id("wizardsMenuItem");
    
          //public static readonly By helpIcon = By.Id("ngcHelpItem");
        }
    
      }
    
    }


    Other parts of this pretty massive solution use this Settings page, so it looks to me like it should work. Anybody see my blunder?

    (Funny how a line of code can hold you up all day.)

    If I try to put "using Settings;" it says:

    the type or namespace name "Settings' could not be found (are you missing a using directive or an assembly reference?)

    • Edited by Tom Ruby Monday, June 24, 2019 9:08 PM Added the forgotten error message.
    Monday, June 24, 2019 6:31 PM

Answers

  • The clue is in "are you missing a using directive or an assembly reference?". In the project where the line is not working, you need to add a reference to the dll (or whatever) that contains SettingsPage.

    Here's a pic of one of the solutions I am working on, with the references section highlighted, as an example. You need to go to that bit of your project, right click, select "Add Reference", and so on.

    Monday, June 24, 2019 11:33 PM

All replies

  • Hmm. Moved the code to a different file in a different folder of the app, and now it's quite happy.

    So, we have proved: There's something I don't know about this. (This should not be any surprise.)

    Monday, June 24, 2019 9:32 PM
  • The clue is in "are you missing a using directive or an assembly reference?". In the project where the line is not working, you need to add a reference to the dll (or whatever) that contains SettingsPage.

    Here's a pic of one of the solutions I am working on, with the references section highlighted, as an example. You need to go to that bit of your project, right click, select "Add Reference", and so on.

    Monday, June 24, 2019 11:33 PM
  • Oh. I thought C# would get this info from the Usings... silly me.
    Tuesday, June 25, 2019 1:51 PM