2

I have been trying different solutions I found (maybe this issue is a problem with newer versions of chrome and chromedriver). Anyway, haven't had any luck in the past day. I found various other posts but this issue is not the same. Please read whole thing before marking as a dup. :)

The error: Message: Test method Resolver.NavigationTests.RememberMeValidation threw exception: OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"userMenu"} (Session info: chrome=71.0.3578.98) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64) TestCleanup method Resolver.NavigationTests.CleanUp threw exception. OpenQA.Selenium.NoSuchElementException: OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"userMenu"} (Session info: chrome=71.0.3578.98) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64).

If I run each test individually - they will pass. Run all, only first test ran will pass. 2nd test fails on first action.

I tried:

What I have done/validated:

  • driver.close, driver.quit, driver.dispose in the close method. Seems to be a hangup with the driver. from what I read online, really only need driver.quit

  • I do have the latest chrome browser version and latest version of the chromedriver: (Session info: chrome=71.0.3578.98) (Driver info: chromedriver=2.45.615291 )

  • I did uncheck in the chrome LAN settings: automatically detect settings

  • I do have the chromedriver as an element in the solution as well as installed with the NuGet Package manager (maybe this not necessary to have both, but get same error if i have one and not the other).

  • if i comment out the BrowserActions.Close() in the TestCleanup I see the error for no such element. BUT, if i leave the BrowserActions.Close() - not commented out - then I see this lovely error: OpenQA.Selenium.WebDriverException: Unexpected error. System.Net.WebException: Unable to connect to the remote server --->

The files:

The test file:

[TestClass]
public class NavigationTests:Base
{
    public static string userName = "wayne3@yahoo.com";
    public static string password = "Password1!";

    public static string bogusUserName = "stimpycom";
    public static string bogusPassword = "123";

    [AssemblyInitialize]
    public static void Setup(TestContext context)
    {

        BrowserActions.ChooseDriverInstance("chrome");

        Pages.HomePage.GoTo();
        NUnit.Framework.Assert.IsTrue(Pages.HomePage.IsAt());
        Pages.LoginPage.SetUserName(userName);
        Pages.LoginPage.SetUserPassword(password);

        Pages.LoginPage.LoginIntoApp();
        Base.Extras.Sleep(2000);


    }

    [TestMethod]
    public void Go_toLeftNavigationOption()
    {
        Base.Extras.Sleep(2000);
        Pages.CasesPage.SelectCases();

        Pages.CasesPage.SelectTypeofCases("Active");
        Pages.CasesPage.SelectTypeofCases("Resolved");
        Pages.CasesPage.SelectTypeofCases("Closed");
        Pages.CasesPage.SelectTypeofCases("Recent");
        Pages.CasesPage.SelectTypeofCases("All Cases");
        Pages.EasyEstimatePage.SelectNav("Easy Estimate");
        Pages.ReferACasePage.SelectNav("Refer a Case");
        Pages.QuestionsPage.SelectNav("Questions");
        Pages.SettingsPage.SelectNav("Settings");
        Pages.CasesPage.SelectCases();

    }

    [TestMethod]
    public void Go_toTopNavigationOption()
    {
        Base.Extras.Sleep(2000);
        Pages.NotificationsTopNav.OpenNotificationsTopNav();

        //user pulldown - My Profile and Logout
        Pages.UserMenu.OpenUserMenu();
        Pages.UserMenu.OpenMyProfile();

        //Search
        //Pages.CaseSearch.SearchForCase();


    }

    [TestMethod]
    public void RememberMeValidation()
    {
        //already logged in via the setup
        //log out first
        Pages.UserMenu.OpenUserMenu();
        Pages.UserMenu.Logout();
        //set the user name and password
        Pages.LoginPage.SetUserName(userName);
        Pages.LoginPage.SetUserPassword(password);

        //check the remember me check box
        Pages.LoginPage.CheckRememberMe();
        Pages.LoginPage.LoginIntoApp();
        Base.Extras.Sleep(2000);

        //log out
        Pages.UserMenu.OpenUserMenu();
        Pages.UserMenu.Logout();

        //only enter the user password ID to login
        Pages.LoginPage.SetUserPassword(password);
        Pages.LoginPage.LoginIntoApp();
        Base.Extras.Sleep(2000);

    }

    [TestMethod]
    public void InvalidLogin()
    {
        //already logged in via the setup
        //log out first
        Pages.UserMenu.OpenUserMenu();
        Pages.UserMenu.Logout();

        //click in the email/username and password fields - leave blank
        Pages.LoginPage.SetUserName("");

        Pages.LoginPage.ValidateMissingUsername();
        Pages.LoginPage.SetUserPassword("");


        Pages.LoginPage.ValidateMissingPassword();

        Pages.LoginPage.ValidateLoginNotEnabled();


        //enter just password
        Pages.LoginPage.SetUserPassword(password);

        Pages.LoginPage.ValidateLoginNotEnabled();


        //set the user name and password to bogus values
        Pages.LoginPage.SetUserName(bogusUserName);
        Pages.LoginPage.SetUserPassword(bogusPassword);

        Pages.LoginPage.ValidateLoginNotEnabled();


        //validate can log in
        Pages.HomePage.GoTo();
        Pages.LoginPage.SetUserName(userName);
        Pages.LoginPage.SetUserPassword(password);

        Pages.LoginPage.LoginIntoApp();
        Base.Extras.Sleep(150);



    }


    [TestCleanup]
    public void CleanUp()
    {
        Pages.UserMenu.OpenUserMenu();
        Pages.UserMenu.Logout();
        BrowserActions.Close();


    }



}

The BrowserActions file: namespace Resolver { public enum BrowserType { Chrome, Firefox, IE, Edge }

public class BrowserActions
{
    public BrowserType _browserType;
    public static IWebDriver webDriver;// = new InternetExplorerDriver();//new FirefoxDriver();


    public static string Title
    {
        get { return webDriver.Title; }

    }


    public static ISearchContext Driver
    {
        get { return webDriver; }

    }

    public static void Goto(string url)
    {

        webDriver.Url = url;
        webDriver.Manage().Window.Maximize();
        Thread.Sleep(5000);
        webDriver.Manage().Cookies.DeleteAllCookies();
    }

    public static void ScrollToBottom()//IWebDriver driver
    {
        long scrollHeight = 0;

        do
        {
            IJavaScriptExecutor js = (IJavaScriptExecutor)webDriver;
            var newScrollHeight = (long)js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight); return document.body.scrollHeight;");

            if (newScrollHeight == scrollHeight)
            {
                break;
            }
            else
            {
                scrollHeight = newScrollHeight;
                Thread.Sleep(400);
            }
        } while (true);
    }

    public BrowserActions(BrowserType browser)
    {
        _browserType = browser;
    }

    public static void ChooseDriverInstance(string browser)  //BrowserType browserType)
    {
        switch (browser)
        {
            case "chrome":
                webDriver = new ChromeDriver();
                break;

            case "ie":
                var options = new InternetExplorerOptions()
                {
                    //InitialBrowserUrl = baseURL,
                    IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                    IgnoreZoomLevel = true,
                    EnableNativeEvents = false,
                    RequireWindowFocus = false,
                    //maybe helpful
                    UnhandledPromptBehavior = UnhandledPromptBehavior.Accept,
                    EnablePersistentHover = true,
                    EnsureCleanSession = true

                };

                webDriver = new InternetExplorerDriver(options);
                break;

            case "firefox":
                webDriver = new FirefoxDriver();
                break;

            default:
                webDriver = new ChromeDriver();
                break;


        }


    }
    public static void Close()
    {
        webDriver.Quit();
        //webDriver.Dispose();
        //webDriver.Close();
        Console.WriteLine("Closed the browser");
    }

}

}

Any helpful advice would be greatly appreciated.

JSoldano
  • 81
  • 1
  • 4

0 Answers0