Pregunta

I have the following HTML code:

div id="flashMessage" class="error"> 
<span>Saved Section.</span>
<div id="errors" class="clearfix">
</div>

I would like to get the text which is contained in span, I tried all the locators.

Could someone please help me with the respective command and css or xpath locator in selenium, for the above query?

¿Fue útil?

Solución

This should work for you:

string spanText = driver.findElement(By.cssSelector("div#flashMessage>span")).getText();

I'm not sure why the same locator wouldn't work for success messages, but you can try this:

string spanText = driver.findElement(By.cssSelector("div#flashMessage.msg>span")).getText();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top