Reputation: 71
I am getting below error every time when trying to verify the user credentials after login.
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//td[contains(text(), 'User: Naveen K')]"}
My code is as follows
@Test(priority = 2)
public void verifyUserNameLabelTest() {
testUtil.switchToFrame();
Assert.assertTrue(homePage.verifyUserName());
}
public void switchToFrame() {
driver.switchTo().frame("mainpanel");
}
public boolean verifyUserName() {
return usernameLabel.isDisplayed();
}
My HTML web page source code is as follows
Upvotes: 1
Views: 1527
Reputation: 4749
Answer of @rajKamal is nice, but you can also use "." to search the name like that
"//td/font[contains(., 'User: Naveen K')]"}
Upvotes: 0
Reputation: 674
Problem is with your xpath, which tries to find user element:
"//td[contains(text(), 'User: Naveen K')]"}
Correct xpath would be:
"//td/font[contains(text(), 'User: Naveen K')]"}
Text which you are looking does not belong to td tag, instead it's belong to font tag.
Upvotes: 4