title: No such element: Unable to locate element: exception coming in selenium
body: <p>I am getting below error every time when trying to verify the user credentials after login.</p>
  
  <blockquote>
    <p>org.openqa.selenium.NoSuchElementException: no such element: Unable to
    locate element: {"method":"xpath","selector":"//td[contains(text(),
    'User: Naveen K')]"}</p>
  </blockquote>
  
  <p>My code is as follows</p>
  
  <h1>Home page test class</h1>
  
  <pre><code>@Test(priority = 2)
  public void verifyUserNameLabelTest() {
  
      testUtil.switchToFrame();       
  
      Assert.assertTrue(homePage.verifyUserName());
  
  }
  </code></pre>
  
  <h1>TestUtil class</h1>
  
  <pre><code>public void switchToFrame() {
  
      driver.switchTo().frame("mainpanel");
  
  }
  </code></pre>
  
  <h1>Home page class</h1>
  
  <pre><code>public boolean verifyUserName() {
  
      return usernameLabel.isDisplayed();
  
  } 
  </code></pre>
  
  <p>My HTML web page source code is as follows</p>
  
  <p><a href="https://i.stack.imgur.com/pmtMO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pmtMO.png" alt="img"></a></p>