Here is the sample:

WebElement LoginLabel = driver.findElement(location);
assert LoginLabel.getAttribute("textContent").equals("Login ID");

Above code fails while asserting but when I try to print the textContent, Eclipse console shows only Login ID (which is expected).

WebElement LoginLabel = driver.findElement(location);
String S = LoginLabel.getAttribute("textContent");
assert LoginLabel.getAttribute("textContent").equals("Login ID");

It is throwing


while executing last line.

Test case successfully running when I use 'contains'. as shown below

assert LoginLabel.getAttribute("textContent").contains("Login ID");

What is the difference between contains and equals here. Is it fine to use contains or Am I missing something. Please help me with this. I am new to selenium.

1 Answer 1


Obviously, label contains some extra characters beyond "Login ID". Could be spaces. Print it out to find out what it is.

Your problem is (IMHO) not being new to Selenium but being new to programming in general. No worries, with time you will develop good judgement.

As they say: "To avoid mistakes you need good judgement. Good judgement comes from experience. Experience comes from making a lot of mistakes". :-) So you are on your way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.