Take the 2-minute tour ×

I'm basically writing a testcase to determine if a status shared on Facebook was actually shared. Below is the xpath for getting the text of first post on Facebook. I want to compare it to the status I posted e.g 'Blah'. I've been trying to use AssertEquals but that doesn't seem to be working.

 WebElement status = getElement(By.Xpath("//div[@id='pagelet_home_stream']//ul[@id = 'home_stream']//li[1]//span[@class='userContent']")

 AssertEquals(status, "Blah");
share|improve this question
It may be a timing issue. See this post: stackoverflow.com/questions/5817185/… –  aetheria Oct 6 '12 at 10:29
Can you show more of the code - e.g. the assertEquals(), how you obtain the value of the element. The XPath expression itself looks fine. –  aetheria Oct 6 '12 at 10:30
Added the AssertEquals statement. –  Komal Waseem Oct 6 '12 at 15:01
add comment

1 Answer

You need to call element.getText() otherwise you're comparing with a WebElement object rather than a String. Also, it's important that the expected text goes first in the assertEquals(expected, actual) otherwise you get a confusing message when they don't match.

assertEquals("Blah", status.getText());
share|improve this answer
add comment

Your Answer


