0

I am getting the following error while trying to verify an assertion. I tried adding wait, but it didn't help.

Error message:

java.lang.AssertionError: expected:<Risk Assessment Form: Completed> 
but was:<[[ChromeDriver: chrome on XP 
(73e81e18d39e6aaa89afd908b8438a82)] -> css selector: div.container-fluid > h3]>

The following is the code that I am writing:

 page2.selectCreateRiskAssessment();
 new WebDriverWait(driver, 30).until(
              ExpectedConditions.presenceOfAllElementsLocatedBy(
              By.linkText("View Risk Assessment"))
 ); 
 assertEquals("Risk Assessment Form: Completed",
              driver.findElement(By.cssSelector("div.container-fluid > h3"))
 );     
1
driver.findElement(By.cssSelector("div.container-fluid > h3"))

The findElement returns a WebElement and not its text and thus you cannot compare them like that.

WebElements have a function getText() to return the text of the object.

The assert should look like this:

assertEquals("Risk Assessment Form: Completed", 
             driver.findElement(By.cssSelector("div.container-fluid > h3")).getText());
  • Thank you for your help. I was not able to figure out what was the issue and i didnt realize that i am not using .getText(). It is working fine now. Thanks. – Meenakshi Apr 30 '15 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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