Frage

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?

War es hilfreich?

Lösung

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();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top