Domanda

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?

È stato utile?

Soluzione

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();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top