Your cast isn't successful because there isn't really anything to cast into a string from a webelement. You might invoke java.lang.objects toString() method but you'll simply get the hash representation of your object.
If you want to extract the text of the Element e.g. "This is a Text" in the following snippet
<div>
<span id="text"> This is a Text</span>
</div>
you might use driver.findElement(By.xpath("//div/span[@id='text']")).getText();
.
In my experience getText does sometimes behave quite unpredictable regarding it's return types (sometimes empty strings, sometimes null) which is a serious problem if you use it in a method like
public Boolean textMatches(String exp, WebElement elem){
return elem.getText().equals(exp);
}
because you'll get an uncaught null pointer if it returns null. So I prefer something along the lines of
public Boolean textMatches(String exp, WebElement elem){
String val = (String)((JavascriptExecutor)driver).executeScript("return (arguments[0].innerText)?arguments[0].innerText: ''", elem);
return val.equals(exp);
}
since you can be sure that your value will always be a String.