title: Issue in Login in Page Object Model
body: <p>I have a use case which denotes below steps
  I am trying to implement it using POM in Nunit.</p>
  
  <ol>
  <li>Open Login Form</li>
  <li><p>Feed the data in the username and password fields using Excel.</p>
  
  <p>3a. <strong>If the credentials are correct</strong></p>
  
  <p>a)Log the test case as passed</p>
  
  <p>b)Click on Log Off link</p></li>
  </ol>
  
  <p>4.Close the remaining browser window</p>
  
  <p>3b.<strong>If the credentials are incorrect</strong></p>
  
  <p>a) Log the test case as failed</p>
  
  <p>b) Clear the username and password textboxes</p>
  
  <p>c) No need to close the browser window.</p>
  
  <p>Now the issue is already driver is instantiated in [Setup] in Main Class.
  How do we instantiate the browser window again in case the login is successful.</p>
  
  <p>I am adding the below code</p>
  
  <pre><code>Login Object Class
  using NUnit.Framework;
  using OpenQA.Selenium;
  using OpenQA.Selenium.Chrome;
  using OpenQA.Selenium.Support.UI;
  using SeleniumExtras.PageObjects;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace PracticePrograms.PageObjectsWithPageFactory
  {
  public class VSSLoginObjects
  {
      [FindsBy(How = How.Id, Using = "userNameOldLook")]
      public IWebElement Userid { get; set; }
  
      [FindsBy(How = How.XPath, Using = "//input[@type='password']")]
      public IWebElement Password { get; set; }
  
      [FindsBy(How = How.XPath, Using = "//a[contains(text(),'login')]")]
      public IWebElement Btn_Login { get; set; }
  
      [FindsBy(How = How.XPath, Using = "//li[contains(text(),'Login failed')]")]
      public IWebElement Lbl_Login_Failed { get; set; }
  
      [FindsBy(How = How.XPath, Using = "//a[contains(text(),'Logoff')]")]
      public IWebElement lnk_logoff;
  
  
      public VSSLoginObjects()
      {
          PageFactory.InitElements(DriverInstance.driver, this);
      }
  
      public void Login_QAPortal()
      {
          Userid.SendKeys("v0c1344");
          Wait.UntilElementDisplayed(DriverInstance.driver, Password);
          Password.SendKeys("welcome5");
          Btn_Login.Click();
          //return new QAPortal_LandingPage_Objects();
  
      }
      public void Test_Login_QA_Portal()
      {
          String Excel = @"C:\\Selenium Files\\TestData.xlsx";
          int length = ExcelClassTemp.GetRowCount(Excel, 3);
          for (int i = 2; i &lt;= length; i++)
          {
  
              String data = ExcelClassTemp.ReadExcel(Excel, 3, i, 1);
              String upper_data = data.ToUpper();
              Userid.SendKeys(upper_data);
              Password.SendKeys("Welcome567");
              Btn_Login.Click();
  
              if (DriverInstance.driver.PageSource.Contains("Trucks Portal"))
              {
                  Console.WriteLine("User Credentials" + upper_data + "Passed");
                  lnk_logoff.Click();
                  DriverInstance.driver.Close();
  
              }
              else
              {
                  Console.WriteLine("User Credentials" + upper_data + "Failed");
                  Userid.Clear();
                  Password.Clear();
              }
  
  
  
          }
  
      }
     }
     }
  </code></pre>
  
  <p>Adding the Main Class</p>
  
  <pre><code>Main Class
  using System;
  using System.Linq;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  using NUnit.Framework;
  using OpenQA.Selenium.Chrome;
  
   namespace PracticePrograms.PageObjectsWithPageFactory
   {
  public class Tests
  {
      [SetUp]
      public void setup()
      {
          DriverInstance.driver = new ChromeDriver();
          DriverInstance.driver.Navigate().GoToUrl("Go to Url");
          DriverInstance.driver.Manage().Window.Maximize();
  
  
      }
  
  
  
      [Test]
      public void Perform_VSS_Login()
      {
          VSSLoginObjects login = new VSSLoginObjects();
          login.Test_Login_QA_Portal();
  
      }
  
  
  
      }
  
  }
  </code></pre>